fix(coding): preserve contextual unicode folding

This commit is contained in:
brother7 committed 2026-08-23 18:36:48 +08:00
1 parent 365c2b0f76
commit 81c3c5b5c3
2 files changed
+6 -3

No files matched your search

+1 -3
View File
@@ -154,7 +154,6 @@ function foldedTextWithOffsets(value: string): {
starts: number[]; starts: number[];
ends: number[]; ends: number[];
} { } {
let text = '';
const starts: number[] = []; const starts: number[] = [];
const ends: number[] = []; const ends: number[] = [];
for (let index = 0; index < value.length;) { for (let index = 0; index < value.length;) {
@@ -163,14 +162,13 @@ function foldedTextWithOffsets(value: string): {
const character = String.fromCodePoint(codePoint); const character = String.fromCodePoint(codePoint);
const end = index + character.length; const end = index + character.length;
const folded = character.toLowerCase(); const folded = character.toLowerCase();
text += folded;
for (let foldedIndex = 0; foldedIndex < folded.length; foldedIndex += 1) { for (let foldedIndex = 0; foldedIndex < folded.length; foldedIndex += 1) {
starts.push(index); starts.push(index);
ends.push(end); ends.push(end);
} }
index = end; index = end;
} }
return { text, starts, ends }; return { text: value.toLowerCase(), starts, ends };
} }
async function fallbackFileList(projectPath: string): Promise<string[]> { async function fallbackFileList(projectPath: string): Promise<string[]> {
+5
View File
@@ -110,6 +110,7 @@ describe('PI-105 project file service', () => {
await mkdir(path.join(root, 'node_modules', 'private-package'), { recursive: true }); await mkdir(path.join(root, 'node_modules', 'private-package'), { recursive: true });
await writeFile(path.join(root, 'docs', 'guide.md'), 'First line\nNeedle and needle again\n', 'utf8'); await writeFile(path.join(root, 'docs', 'guide.md'), 'First line\nNeedle and needle again\n', 'utf8');
await writeFile(path.join(root, 'docs', 'unicode.md'), 'İx needle and NEEDLE\n', 'utf8'); await writeFile(path.join(root, 'docs', 'unicode.md'), 'İx needle and NEEDLE\n', 'utf8');
await writeFile(path.join(root, 'docs', 'greek.md'), 'ΟΣ\n', 'utf8');
await writeFile(path.join(root, 'node_modules', 'private-package', 'secret.txt'), 'needle\n', 'utf8'); await writeFile(path.join(root, 'node_modules', 'private-package', 'secret.txt'), 'needle\n', 'utf8');
const service = new CodingProjectFileService({ const service = new CodingProjectFileService({
async run() { async run() {
@@ -145,5 +146,9 @@ describe('PI-105 project file service', () => {
{ text: 'NEEDLE', start: 14, end: 20 }, { text: 'NEEDLE', start: 14, end: 20 },
], ],
})); }));
expect(await service.search(root, 'ος')).toContainEqual(expect.objectContaining({
path: 'docs/greek.md',
submatches: [{ text: 'ΟΣ', start: 0, end: 2 }],
}));
}); });
}); });