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

Handle insertTranspose for beforeinput event #2764

Merged
merged 1 commit into from
Aug 4, 2022
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
Handle insertTranspose for beforeinput event
  • Loading branch information
fantactuka committed Aug 4, 2022
commit 7053a0254c8cffd23974466031bdac8ccdbb0d08
54 changes: 54 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Keyboard.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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,
E2E_BROWSER,
focusEditor,
html,
initialize,
IS_MAC,
test,
} from '../utils/index.mjs';

const supportsTranspose = IS_MAC && E2E_BROWSER !== 'firefox';

test.describe('Keyboard shortcuts', () => {
test.beforeEach(
({isCollab, page}) => supportsTranspose && initialize({isCollab, page}),
);

test('handles "insertTranspose" event from Control+T on MAC', async ({
page,
context,
isPlainText,
browserName,
}) => {
test.skip(!supportsTranspose);

await focusEditor(page);
await page.keyboard.type('abc');
await page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await page.keyboard.down('Control');
await page.keyboard.press('T');
await page.keyboard.press('T');
await page.keyboard.up('Control');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">bca</span>
</p>
`,
);
});
});
2 changes: 1 addition & 1 deletion packages/lexical/src/LexicalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ function onBeforeInput(event: InputEvent, editor: LexicalEditor): void {
const anchorNode = anchor.getNode();
const focusNode = focus.getNode();

if (inputType === 'insertText') {
if (inputType === 'insertText' || inputType === 'insertTranspose') {
if (data === '\n') {
event.preventDefault();
dispatchCommand(editor, INSERT_LINE_BREAK_COMMAND, false);
Expand Down