fix: try/catch in correct location for regex find and replace

closes #6983
This commit is contained in:
Tom Moor
2024-06-03 20:54:07 -04:00
parent cfc7ae6d04
commit c6423c47b3

View File

@@ -156,14 +156,10 @@ export default class FindAndReplaceExtension extends Extension {
}
private get findRegExp() {
try {
return RegExp(
this.searchTerm.replace(/\\+$/, ""),
!this.options.caseSensitive ? "gui" : "gu"
);
} catch (err) {
return RegExp("");
}
return RegExp(
this.searchTerm.replace(/\\+$/, ""),
!this.options.caseSensitive ? "gui" : "gu"
);
}
private goToMatch(direction: number): Command {
@@ -250,15 +246,19 @@ export default class FindAndReplaceExtension extends Extension {
const search = this.findRegExp;
let m;
while ((m = search.exec(text))) {
if (m[0] === "") {
break;
}
try {
while ((m = search.exec(text))) {
if (m[0] === "") {
break;
}
this.results.push({
from: pos + m.index,
to: pos + m.index + m[0].length,
});
this.results.push({
from: pos + m.index,
to: pos + m.index + m[0].length,
});
}
} catch (e) {
// Invalid RegExp
}
});
}