Skip to content
Open
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
113 changes: 113 additions & 0 deletions packages/lexical-playground/__tests__/e2e/CodeBlock.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {
moveLeft,
moveToEditorBeginning,
moveToEditorEnd,
moveToEnd,
moveToStart,
pressShiftEnter,
Expand Down Expand Up @@ -983,4 +984,116 @@ test.describe('CodeBlock', () => {
);
}
});

for (const key of ['ArrowRight', 'ArrowDown']) {
test(`${key} key should exit from the code block inside the layout`, async ({
page,
isPlainText,
isCollab,
browser,
}) => {
test.skip(isPlainText || isCollab || browser === 'firefox');
await initialize({page});
await focusEditor(page);

await page.keyboard.type('/');
await click(page, '.typeahead-popover .icon.columns');
await click(page, '.Modal__modal .Modal__content .Button__root');

// remove empty paragraphs around the layout
await moveToEditorEnd(page);
await page.keyboard.press('Backspace');
await moveToEditorBeginning(page);
await page.keyboard.press('Backspace');

// Focus on first column
await click(
page,
'.PlaygroundEditorTheme__layoutContainer .PlaygroundEditorTheme__layoutItem:nth-child(1)',
);
await page.keyboard.type('```');
await page.keyboard.press('Enter');

// selection at the code
await assertSelection(page, {
anchorOffset: 0,
anchorPath: [0, 0, 0],
focusOffset: 0,
focusPath: [0, 0, 0],
});
await assertHTML(
page,
html`
<div
class="PlaygroundEditorTheme__layoutContainer"
dir="auto"
style="grid-template-columns: 1fr 1fr">
<div
class="PlaygroundEditorTheme__layoutItem"
dir="auto"
data-lexical-layout-item="true">
<code
class="PlaygroundEditorTheme__code"
dir="auto"
spellcheck="false"
data-gutter="1">
<br />
</code>
</div>
<div
class="PlaygroundEditorTheme__layoutItem"
dir="auto"
data-lexical-layout-item="true">
<p class="PlaygroundEditorTheme__paragraph" dir="auto">
<br />
</p>
</div>
</div>
`,
);

await page.keyboard.press(key);

// selection at the new paragraph but inside the layout
await assertSelection(page, {
anchorOffset: 0,
anchorPath: [0, 0, 1],
focusOffset: 0,
focusPath: [0, 0, 1],
});
await assertHTML(
page,
html`
<div
class="PlaygroundEditorTheme__layoutContainer"
dir="auto"
style="grid-template-columns: 1fr 1fr">
<div
class="PlaygroundEditorTheme__layoutItem"
dir="auto"
data-lexical-layout-item="true">
<code
class="PlaygroundEditorTheme__code"
dir="auto"
spellcheck="false"
data-gutter="1">
<br />
</code>
<p class="PlaygroundEditorTheme__paragraph" dir="auto">
<br />
</p>
</div>
<div
class="PlaygroundEditorTheme__layoutItem"
dir="auto"
data-lexical-layout-item="true">
<p class="PlaygroundEditorTheme__paragraph" dir="auto">
<br />
</p>
</div>
</div>
`,
);
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ test('Layout - removes layout completely when both columns are empty and backspa
});

for (const key of ['ArrowRight', 'ArrowDown']) {
test(`Layout - ${key} keys should exit from the layout if the selection is at the end of the element`, async ({
test(`Layout - ${key} key should exit from the layout if the selection is at the end of the element`, async ({
page,
isPlainText,
isCollab,
browser,
}) => {
test.skip(isPlainText || isCollab);
test.skip(isPlainText || isCollab || browser === 'firefox');
await initialize({page});
await focusEditor(page);

Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ export function $onEscapeUp(
($isElementNode(anchorNode) &&
anchorNode.getFirstDescendant() === firstDescendant))
) {
containerNode.insertBefore($createParagraphNode()).selectEnd();
containerNode.insertBefore($createParagraphNode());
return true;
}
}
Expand Down Expand Up @@ -1124,7 +1124,7 @@ export function $onEscapeDown(
($isElementNode(anchorNode) &&
anchorNode.getLastDescendant() === lastDescendant))
) {
containerNode.insertAfter($createParagraphNode()).selectEnd();
containerNode.insertAfter($createParagraphNode());
return true;
}
}
Expand Down