Skip to content

Commit

Permalink
Fix issue where cmd/ctrl + left arrow after a tab character would cau…
Browse files Browse the repository at this point in the history
…se exception (#6588)
  • Loading branch information
moughxyz authored Sep 6, 2024
1 parent fe4fcfe commit 8a3eb11
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/lexical-code/src/CodeHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,9 @@ function $handleMoveTo(
const focusNode = focus.getNode();
const isMoveToStart = type === MOVE_TO_START;

// Ensure the selection is within the codeblock
if (
!$isSelectionInCode(selection) ||
!($isCodeHighlightNode(anchorNode) || $isTabNode(anchorNode)) ||
!($isCodeHighlightNode(focusNode) || $isTabNode(focusNode))
) {
Expand Down
29 changes: 29 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Tab.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

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

Expand Down Expand Up @@ -114,5 +116,32 @@ test.describe('Tab', () => {
`,
);
});

test('can go to start of line after a tab character', async ({
page,
isPlainText,
}) => {
test.skip(isPlainText);
await focusEditor(page);

await page.keyboard.type('Foo');
await page.keyboard.press('Tab');

page.on('pageerror', (error) => {
throw new Error(`Uncaught exception: ${error.message}`);
});

// Press ctrl + left arrow key to go to start of line
await keyDownCtrlOrMeta(page);
await page.keyboard.press('ArrowLeft');

// ensure cursor is now at beginning of line
await assertSelection(page, {
anchorOffset: 0,
anchorPath: [0, 0, 0],
focusOffset: 0,
focusPath: [0, 0, 0],
});
});
});
/* eslint-enable sort-keys-fix/sort-keys-fix */

0 comments on commit 8a3eb11

Please sign in to comment.