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