fix: Expensive recursive regex when using French language, closes #5939

This commit is contained in:
Tom Moor
2023-10-11 21:32:18 -04:00
parent 0d319d50b8
commit b63cd67c24
2 changed files with 9 additions and 6 deletions

View File

@@ -15,12 +15,15 @@ export default class Suggestion extends Extension {
keys() {
return {
Backspace: (state: EditorState) => {
const textBeforeCursor = state.doc.textBetween(
0,
Math.max(0, state.selection.from - 1)
const { $from } = state.selection;
const textBefore = $from.parent.textBetween(
Math.max(0, $from.parentOffset - 500), // 500 = max match
Math.max(0, $from.parentOffset - 1), // 1 = account for deleted character
null,
"\ufffc"
);
if (this.options.openRegex.test(textBeforeCursor)) {
if (this.options.openRegex.test(textBefore)) {
return false;
}