From def1d2f6dd2caf2c8888f7b256b994a231af3c84 Mon Sep 17 00:00:00 2001 From: fantactuka Date: Tue, 29 Oct 2024 23:26:43 -0400 Subject: [PATCH] #6768 fix to avoid infinite markdown shortcut matchers run --- packages/lexical-markdown/src/MarkdownShortcuts.ts | 5 ++++- .../lexical-playground/__tests__/e2e/Markdown.spec.mjs | 10 ++++++++++ .../src/plugins/MarkdownTransformers/index.ts | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/lexical-markdown/src/MarkdownShortcuts.ts b/packages/lexical-markdown/src/MarkdownShortcuts.ts index 8021296c648..e6b5d7e523c 100644 --- a/packages/lexical-markdown/src/MarkdownShortcuts.ts +++ b/packages/lexical-markdown/src/MarkdownShortcuts.ts @@ -480,10 +480,13 @@ export function registerMarkdownShortcuts( const selection = editorState.read($getSelection); const prevSelection = prevEditorState.read($getSelection); + // We expect selection to be a collapsed range and not match previous one (as we want + // to trigger transforms only as user types) if ( !$isRangeSelection(prevSelection) || !$isRangeSelection(selection) || - !selection.isCollapsed() + !selection.isCollapsed() || + selection.is(prevSelection) ) { return; } diff --git a/packages/lexical-playground/__tests__/e2e/Markdown.spec.mjs b/packages/lexical-playground/__tests__/e2e/Markdown.spec.mjs index b434d62be55..dc8d9a4a18e 100644 --- a/packages/lexical-playground/__tests__/e2e/Markdown.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/Markdown.spec.mjs @@ -595,6 +595,16 @@ test.describe.parallel('Markdown', () => { `, text: 'hello [world](https://www.test.com)!', }, + { + html: html` +

+ 10:20:30😄 +

+ `, + text: '10:20:30:smile:', + }, ]; const NESTED_TEXT_FORMAT_SHORTCUTS = [ diff --git a/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts b/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts index 736267dee54..391e8a7bdb2 100644 --- a/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts +++ b/packages/lexical-playground/src/plugins/MarkdownTransformers/index.ts @@ -100,7 +100,7 @@ export const EMOJI: TextMatchTransformer = { dependencies: [], export: () => null, importRegExp: /:([a-z0-9_]+):/, - regExp: /:([a-z0-9_]+):/, + regExp: /:([a-z0-9_]+):$/, replace: (textNode, [, name]) => { const emoji = emojiList.find((e) => e.aliases.includes(name))?.emoji; if (emoji) {