* Fixes #168068

* Fixes test
This commit is contained in:
Henning Dieterichs 2022-12-06 14:38:52 +01:00 committed by GitHub
parent 62d8f662fb
commit c0799f0308
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 1 deletions

View file

@ -61,7 +61,11 @@ export class UnicodeTextModelHighlighter {
}
}
const str = lineContent.substring(startIndex, endIndex);
const word = getWordAtText(startIndex + 1, DEFAULT_WORD_REGEXP, lineContent, 0);
let word = getWordAtText(startIndex + 1, DEFAULT_WORD_REGEXP, lineContent, 0);
if (word && word.endColumn <= startIndex + 1) {
// The word does not include the problematic character, ignore the word
word = null;
}
const highlightReason = codePointHighlighter.shouldHighlightNonBasicASCII(str, word ? word.word : null);
if (highlightReason !== SimpleHighlightReason.None) {

View file

@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import assert = require('assert');
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import { Range } from 'vs/editor/common/core/range';
import { UnicodeHighlighterOptions, UnicodeTextModelHighlighter } from 'vs/editor/common/services/unicodeTextModelHighlighter';
import { createTextModel } from 'vs/editor/test/common/testTextModel';
suite('UnicodeTextModelHighlighter', () => {
ensureNoDisposablesAreLeakedInTestSuite();
function t(text: string, options: UnicodeHighlighterOptions): unknown {
const m = createTextModel(text);
const r = UnicodeTextModelHighlighter.computeUnicodeHighlights(m, options);
m.dispose();
return {
...r,
ranges: r.ranges.map(r => Range.lift(r).toString())
};
}
test('computeUnicodeHighlights (#168068)', () => {
assert.deepStrictEqual(
t(`
For å gi et eksempel
`, {
allowedCodePoints: [],
allowedLocales: [],
ambiguousCharacters: true,
invisibleCharacters: true,
includeComments: false,
includeStrings: false,
nonBasicASCII: false
}),
{
ambiguousCharacterCount: 0,
hasMore: false,
invisibleCharacterCount: 4,
nonBasicAsciiCharacterCount: 0,
ranges: [
'[2,5 -> 2,6]',
'[2,7 -> 2,8]',
'[2,10 -> 2,11]',
'[2,13 -> 2,14]'
]
}
);
});
});