improve whitespace sensitivity in multiline text matching

This commit is contained in:
Marc Goodner 2024-12-04 07:35:12 -08:00
commit bb7925fe11

View file

@ -232,9 +232,13 @@ function findTextPosition(content: string, searchText: string): Position {
throw new Error(`Text not found:\n${searchText}`); throw new Error(`Text not found:\n${searchText}`);
} }
// Map back to original content position
const originalPos = content.slice(0, pos).replace(/[ \t]+/g, ' ').length;
const originalEnd = originalPos + searchText.length;
return { return {
start: pos, start: pos,
end: pos + searchText.length, end: originalEnd,
lineNumber: normalized.slice(0, pos).split('\n').length lineNumber: normalized.slice(0, pos).split('\n').length
}; };
} }