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;
}

View File

@@ -14,7 +14,7 @@ import { SuggestionsMenuType } from "../plugins/Suggestions";
import emojiRule from "../rules/emoji";
/**
* Languages using the colon character with a space infront in standard
* Languages using the colon character with a space in front in standard
* punctuation. In this case the trigger is only matched once there is additional
* text after the colon.
*/
@@ -34,7 +34,7 @@ export default class Emoji extends Suggestion {
return {
type: SuggestionsMenuType.Emoji,
openRegex: new RegExp(
`(?:^|\\s):([0-9a-zA-Z_+-]+)${languageIsUsingColon ? "+" : "?"}$`
`(?:^|\\s):([0-9a-zA-Z_+-]+)${languageIsUsingColon ? "" : "?"}$`
),
closeRegex:
/(?:^|\s):(([0-9a-zA-Z_+-]*\s+)|(\s+[0-9a-zA-Z_+-]+)|[^0-9a-zA-Z_+-]+)$/,