Skip to content

Commit

Permalink
#6768 fix to avoid infinite markdown shortcut matchers run
Browse files Browse the repository at this point in the history
  • Loading branch information
fantactuka committed Oct 30, 2024
1 parent 07ca5c8 commit def1d2f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/lexical-markdown/src/MarkdownShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Markdown.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,16 @@ test.describe.parallel('Markdown', () => {
`,
text: 'hello [world](https://www.test.com)!',
},
{
html: html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">10:20:30😄</span>
</p>
`,
text: '10:20:30:smile:',
},
];

const NESTED_TEXT_FORMAT_SHORTCUTS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit def1d2f

Please sign in to comment.