From 89f51a16d37dbd5cfdbbc64f39502819421eba4d Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Wed, 27 Nov 2024 12:32:05 -0700 Subject: [PATCH] fix: some letters have multiple char codes. fixes #6574 --- .../src/lib/textValidation/lineValidatorFactory.test.ts | 3 ++- .../cspell-lib/src/lib/textValidation/lineValidatorFactory.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.test.ts b/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.test.ts index 422883875bd..c1755b33ffb 100644 --- a/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.test.ts +++ b/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.test.ts @@ -11,6 +11,7 @@ describe('lineValidatorFactory', () => { word | expected ${'one'} | ${[]} ${'three etc.'} | ${[]} + ${'three etc. 𐀀𐃘'} | ${[]} ${'flip-flop'} | ${[oc({ text: 'flip-flop', isFlagged: true })]} ${'one flip-flop.'} | ${[oc({ text: 'flip-flop', isFlagged: true })]} ${'one two three etc'} | ${[oc({ text: 'etc' })]} @@ -18,7 +19,7 @@ describe('lineValidatorFactory', () => { ${'lion'} | ${[oc({ text: 'lion', suggestionsEx: [oc({ word: 'tiger', isPreferred: true })] })]} `('textValidatorFactory', ({ word, expected }) => { const dict = getDict(); - const tv = textValidatorFactory(dict, { ignoreCase: true, minWordLength: 1 }); + const tv = textValidatorFactory(dict, { ignoreCase: true, minWordLength: 3 }); const r = [...tv.validate({ text: word, range: [10, 10 + word.length] })]; expect(r).toEqual(expected); }); diff --git a/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.ts b/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.ts index 27ddd18ae50..e7eec094fd2 100644 --- a/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.ts +++ b/packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.ts @@ -159,7 +159,7 @@ export function lineValidatorFactory(sDict: SpellingDictionary, options: Validat const line = lineSegment.line; function isWordTooShort(word: TextOffsetRO, ignoreSuffix = false): boolean { - if (word.text.length >= minWordLength) return false; + if (word.text.length >= minWordLength * 2 || [...word.text].length >= minWordLength) return false; const offset = word.offset - line.offset; assert.equal(line.text.slice(offset, offset + word.text.length), word.text); const prefix = [...line.text.slice(Math.max(0, offset - 2), offset)];