improve whitespace sensitivity in multiline text matching
This commit is contained in:
parent
1ec75e87fc
commit
bb7925fe11
1 changed files with 5 additions and 1 deletions
|
|
@ -231,10 +231,14 @@ function findTextPosition(content: string, searchText: string): Position {
|
||||||
if (pos === -1) {
|
if (pos === -1) {
|
||||||
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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue