From fca75edfb84109415ed4781c8f7026f99af83629 Mon Sep 17 00:00:00 2001 From: Mike Watson Date: Thu, 24 Oct 2024 12:30:42 -0400 Subject: [PATCH] AI Assistant: Write Brief should not flag words like '2nd' and '100th' as spelling errors. (#39880) * AI Assistant: Write Brief should not flag words like '2nd' and '100th' as spelling errors. * changelog * Typescript expects isNaN to be passed a number --- .../changelog/fix-write-brief-spellcheck-numbers | 4 ++++ .../breve/features/spelling-mistakes/index.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) 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. 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..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 @@ -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( Number( word ) ) ) { + return; + } + // Split words by hyphens and slashes const subWords = word.split( /[-/]/ );