From f5973c1fed49f000a4c24c049d200f5efa2ca6c9 Mon Sep 17 00:00:00 2001 From: Mike Watson Date: Wed, 23 Oct 2024 10:14:57 -0400 Subject: [PATCH 1/3] AI Assistant: Write Brief should not flag words like '2nd' and '100th' as spelling errors. --- .../breve/features/spelling-mistakes/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts index 44e5ac13094a2..b9a305f57a550 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts @@ -185,9 +185,9 @@ export default function spellingMistakes( text: string ): Array< HighlightedText // \p{M} matches any Unicode mark (combining characters) // The regex has three main parts: // 1. [@#+$/]{0,1} - Optionally matches a single special character at the start - // 2. [\p{L}\p{M}'-]+ - Matches one or more letters, marks, apostrophes, or hyphens - // 3. (?:\/[\p{L}\p{M}'-]+)* - Optionally matches additional parts separated by slashes - const wordRegex = new RegExp( /[@#+$/]{0,1}[\p{L}\p{M}'-]+(?:\/[\p{L}\p{M}'-]+)*/gu ); + // 2. [\p{L}\p{M}\p{N}'-]+ - Matches one or more letters, marks, numbers, apostrophes, or hyphens + // 3. (?:\/[\p{L}\p{M}\p{N}'-]+)* - Optionally matches additional parts separated by slashes + const wordRegex = new RegExp( /[@#+$/]{0,1}[\p{L}\p{M}\p{N}'-]+(?:\/[\p{L}\p{M}\p{N}'-]+)*/gu ); const matches = Array.from( text.matchAll( wordRegex ) ); matches.forEach( match => { @@ -199,6 +199,11 @@ export default function spellingMistakes( text: string ): Array< HighlightedText return; } + // Skip anything that is a valid number + if ( ! isNaN( word ) ) { + return; + } + // Split words by hyphens and slashes const subWords = word.split( /[-/]/ ); From 9874f45fa914b14abcc9316aa51ac7b006c3dea1 Mon Sep 17 00:00:00 2001 From: Mike Watson Date: Wed, 23 Oct 2024 10:16:13 -0400 Subject: [PATCH 2/3] changelog --- .../jetpack/changelog/fix-write-brief-spellcheck-numbers | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/fix-write-brief-spellcheck-numbers diff --git a/projects/plugins/jetpack/changelog/fix-write-brief-spellcheck-numbers b/projects/plugins/jetpack/changelog/fix-write-brief-spellcheck-numbers new file mode 100644 index 0000000000000..28a48a83cba5d --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-write-brief-spellcheck-numbers @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +AI Assistant: Write Brief should not flag words like '2nd' and '100th' as spelling errors. From 2da6965acd74819021f6e80646a025bd37697234 Mon Sep 17 00:00:00 2001 From: Mike Watson Date: Wed, 23 Oct 2024 10:57:22 -0400 Subject: [PATCH 3/3] Typescript expects isNaN to be passed a number --- .../components/breve/features/spelling-mistakes/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts index b9a305f57a550..78ce2847dcb0c 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/spelling-mistakes/index.ts @@ -200,7 +200,7 @@ export default function spellingMistakes( text: string ): Array< HighlightedText } // Skip anything that is a valid number - if ( ! isNaN( word ) ) { + if ( ! isNaN( Number( word ) ) ) { return; }