Skip to content

Commit eb7d564

Browse files
authored
Handle insertTranspose for beforeinput event (#2764)
1 parent 12a2f8e commit eb7d564

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
import {
10+
assertHTML,
11+
E2E_BROWSER,
12+
focusEditor,
13+
html,
14+
initialize,
15+
IS_MAC,
16+
test,
17+
} from '../utils/index.mjs';
18+
19+
const supportsTranspose = IS_MAC && E2E_BROWSER !== 'firefox';
20+
21+
test.describe('Keyboard shortcuts', () => {
22+
test.beforeEach(
23+
({isCollab, page}) => supportsTranspose && initialize({isCollab, page}),
24+
);
25+
26+
test('handles "insertTranspose" event from Control+T on MAC', async ({
27+
page,
28+
context,
29+
isPlainText,
30+
browserName,
31+
}) => {
32+
test.skip(!supportsTranspose);
33+
34+
await focusEditor(page);
35+
await page.keyboard.type('abc');
36+
await page.keyboard.press('ArrowLeft');
37+
await page.keyboard.press('ArrowLeft');
38+
await page.keyboard.down('Control');
39+
await page.keyboard.press('T');
40+
await page.keyboard.press('T');
41+
await page.keyboard.up('Control');
42+
43+
await assertHTML(
44+
page,
45+
html`
46+
<p
47+
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
48+
dir="ltr">
49+
<span data-lexical-text="true">bca</span>
50+
</p>
51+
`,
52+
);
53+
});
54+
});

packages/lexical/src/LexicalEvents.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function onBeforeInput(event: InputEvent, editor: LexicalEditor): void {
438438
const anchorNode = anchor.getNode();
439439
const focusNode = focus.getNode();
440440

441-
if (inputType === 'insertText') {
441+
if (inputType === 'insertText' || inputType === 'insertTranspose') {
442442
if (data === '\n') {
443443
event.preventDefault();
444444
dispatchCommand(editor, INSERT_LINE_BREAK_COMMAND, false);

0 commit comments

Comments
 (0)