Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix markdown list merging #4387

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/lexical-markdown/src/MarkdownTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,23 @@ const LIST_INDENT_SIZE = 4;
const listReplace = (listType: ListType): ElementTransformer['replace'] => {
return (parentNode, children, match) => {
const previousNode = parentNode.getPreviousSibling();
const nextNode = parentNode.getNextSibling();
const listItem = $createListItemNode(
listType === 'check' ? match[3] === 'x' : undefined,
);
if ($isListNode(previousNode) && previousNode.getListType() === listType) {
if ($isListNode(nextNode) && nextNode.getListType() === listType) {
const firstChild = nextNode.getFirstChild();
if (firstChild !== null) {
firstChild.insertBefore(listItem);
} else {
// should never happen, but let's handle gracefully, just in case.
nextNode.append(listItem);
}
parentNode.remove();
} else if (
$isListNode(previousNode) &&
previousNode.getListType() === listType
) {
previousNode.append(listItem);
parentNode.remove();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import {
assertHTML,
focusEditor,
html,
initialize,
test,
} from '../utils/index.mjs';

test.describe('Regression test #3433', () => {
test.beforeEach(({isCollab, page}) => initialize({isCollab, page}));
test('can merge markdown lists created immediately before existing lists', async ({
page,
isPlainText,
}) => {
test.skip(isPlainText);
await focusEditor(page);
await page.keyboard.press('Enter');
await page.keyboard.type('- one');
await page.keyboard.press('ArrowUp');
await page.keyboard.type('- two');
await assertHTML(
page,
html`
<ul class="PlaygroundEditorTheme__ul">
<li
value="1"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">two</span>
</li>
<li
value="2"
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">one</span>
</li>
</ul>
`,
);
});
});
Loading