mirror of
https://github.com/facebook/lexical.git
synced 2025-08-06 16:39:33 +08:00
[lexical] Bug Fix: Fix forward line deletion when using control+K (#7412)
This commit is contained in:
@ -259,6 +259,62 @@ test.describe.parallel('Selection', () => {
|
|||||||
await assertHTML(page, lines(''));
|
await assertHTML(page, lines(''));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('can delete text by line forwards with control+K', async ({
|
||||||
|
page,
|
||||||
|
isPlainText,
|
||||||
|
}) => {
|
||||||
|
const deleteLineForwardWithControlK = async () => {
|
||||||
|
await page.keyboard.down('Control');
|
||||||
|
await page.keyboard.press('k');
|
||||||
|
await page.keyboard.up('Control');
|
||||||
|
};
|
||||||
|
|
||||||
|
test.skip(isPlainText || !IS_MAC);
|
||||||
|
await focusEditor(page);
|
||||||
|
await page.keyboard.type('One');
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
await page.keyboard.type('Two');
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
await page.keyboard.type('Three');
|
||||||
|
|
||||||
|
const p = (text) =>
|
||||||
|
text
|
||||||
|
? html`
|
||||||
|
<p
|
||||||
|
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
|
||||||
|
dir="ltr">
|
||||||
|
<span data-lexical-text="true">${text}</span>
|
||||||
|
</p>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<p class="PlaygroundEditorTheme__paragraph"><br /></p>
|
||||||
|
`;
|
||||||
|
const lines = (...args) => html`
|
||||||
|
${args.map(p).join('')}
|
||||||
|
`;
|
||||||
|
await assertHTML(page, lines('One', 'Two', '', 'Three'));
|
||||||
|
// Move to the end of the line of 'Two'
|
||||||
|
await moveUp(page, 2);
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines('One', 'Two', 'Three'));
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines('One', 'TwoThree'));
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines('One', 'Two'));
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines('One', 'Two'));
|
||||||
|
await moveToEditorBeginning(page);
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines('', 'Two'));
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines('Two'));
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines(''));
|
||||||
|
await deleteLineForwardWithControlK(page);
|
||||||
|
await assertHTML(page, lines(''));
|
||||||
|
});
|
||||||
|
|
||||||
test('can delete line which ends with element backwards with CMD+delete', async ({
|
test('can delete line which ends with element backwards with CMD+delete', async ({
|
||||||
page,
|
page,
|
||||||
isPlainText,
|
isPlainText,
|
||||||
|
@ -1178,7 +1178,7 @@ function onKeyDown(event: KeyboardEvent, editor: LexicalEditor): void {
|
|||||||
} else if (isDeleteLineBackward(key, metaKey)) {
|
} else if (isDeleteLineBackward(key, metaKey)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
dispatchCommand(editor, DELETE_LINE_COMMAND, true);
|
dispatchCommand(editor, DELETE_LINE_COMMAND, true);
|
||||||
} else if (isDeleteLineForward(key, metaKey)) {
|
} else if (isDeleteLineForward(key, metaKey, ctrlKey)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
dispatchCommand(editor, DELETE_LINE_COMMAND, false);
|
dispatchCommand(editor, DELETE_LINE_COMMAND, false);
|
||||||
} else if (isBold(key, altKey, metaKey, ctrlKey)) {
|
} else if (isBold(key, altKey, metaKey, ctrlKey)) {
|
||||||
|
@ -911,8 +911,15 @@ export function isDeleteLineBackward(key: string, metaKey: boolean): boolean {
|
|||||||
return IS_APPLE && metaKey && isBackspace(key);
|
return IS_APPLE && metaKey && isBackspace(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDeleteLineForward(key: string, metaKey: boolean): boolean {
|
export function isDeleteLineForward(
|
||||||
return IS_APPLE && metaKey && isDelete(key);
|
key: string,
|
||||||
|
metaKey: boolean,
|
||||||
|
ctrlKey: boolean,
|
||||||
|
): boolean {
|
||||||
|
return (
|
||||||
|
IS_APPLE &&
|
||||||
|
((metaKey && isDelete(key)) || (ctrlKey && key.toLowerCase() === 'k'))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDeleteBackward(
|
export function isDeleteBackward(
|
||||||
|
Reference in New Issue
Block a user