diff --git a/resources/js/wysiwyg/lexical/core/LexicalEvents.ts b/resources/js/wysiwyg/lexical/core/LexicalEvents.ts index 2d197ccc2..7d87d9055 100644 --- a/resources/js/wysiwyg/lexical/core/LexicalEvents.ts +++ b/resources/js/wysiwyg/lexical/core/LexicalEvents.ts @@ -99,7 +99,6 @@ import { getNearestEditorFromDOMNode, getWindow, isAt, isBackspace, - isBold, isCopy, isCut, isDelete, @@ -111,7 +110,6 @@ import { isDeleteWordForward, isEscape, isFirefoxClipboardEvents, - isItalic, isLexicalEditor, isLineBreak, isModifier, @@ -128,7 +126,6 @@ import { isSelectionWithinEditor, isSpace, isTab, - isUnderline, isUndo, } from './LexicalUtils'; @@ -479,7 +476,6 @@ function onClick(event: PointerEvent, editor: LexicalEditor): void { } function onPointerDown(event: PointerEvent, editor: LexicalEditor) { - // TODO implement text drag & drop const target = event.target; const pointerType = event.pointerType; if (target instanceof Node && pointerType !== 'touch') { @@ -1064,15 +1060,6 @@ function onKeyDown(event: KeyboardEvent, editor: LexicalEditor): void { dispatchCommand(editor, DELETE_LINE_COMMAND, false); } else if (isAt(key)) { dispatchCommand(editor, KEY_AT_COMMAND, event); - } else if (isBold(key, altKey, metaKey, ctrlKey)) { - event.preventDefault(); - dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'bold'); - } else if (isUnderline(key, altKey, metaKey, ctrlKey)) { - event.preventDefault(); - dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'underline'); - } else if (isItalic(key, altKey, metaKey, ctrlKey)) { - event.preventDefault(); - dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'italic'); } else if (isTab(key, altKey, ctrlKey, metaKey)) { dispatchCommand(editor, KEY_TAB_COMMAND, event); } else if (isUndo(key, shiftKey, metaKey, ctrlKey)) { diff --git a/resources/js/wysiwyg/lexical/core/LexicalUtils.ts b/resources/js/wysiwyg/lexical/core/LexicalUtils.ts index b0bf2f180..cff86a74a 100644 --- a/resources/js/wysiwyg/lexical/core/LexicalUtils.ts +++ b/resources/js/wysiwyg/lexical/core/LexicalUtils.ts @@ -783,39 +783,6 @@ export function isTab( return key === 'Tab' && !altKey && !ctrlKey && !metaKey; } -export function isBold( - key: string, - altKey: boolean, - metaKey: boolean, - ctrlKey: boolean, -): boolean { - return ( - key.toLowerCase() === 'b' && !altKey && controlOrMeta(metaKey, ctrlKey) - ); -} - -export function isItalic( - key: string, - altKey: boolean, - metaKey: boolean, - ctrlKey: boolean, -): boolean { - return ( - key.toLowerCase() === 'i' && !altKey && controlOrMeta(metaKey, ctrlKey) - ); -} - -export function isUnderline( - key: string, - altKey: boolean, - metaKey: boolean, - ctrlKey: boolean, -): boolean { - return ( - key.toLowerCase() === 'u' && !altKey && controlOrMeta(metaKey, ctrlKey) - ); -} - export function isParagraph(key: string, shiftKey: boolean): boolean { return isReturn(key) && !shiftKey; } diff --git a/resources/js/wysiwyg/services/shortcuts.ts b/resources/js/wysiwyg/services/shortcuts.ts index 2702b5486..f66665703 100644 --- a/resources/js/wysiwyg/services/shortcuts.ts +++ b/resources/js/wysiwyg/services/shortcuts.ts @@ -1,4 +1,11 @@ -import {$getSelection, COMMAND_PRIORITY_HIGH, FORMAT_TEXT_COMMAND, KEY_ENTER_COMMAND, LexicalEditor} from "lexical"; +import { + $getSelection, + COMMAND_PRIORITY_HIGH, + FORMAT_TEXT_COMMAND, + KEY_ENTER_COMMAND, + LexicalEditor, + TextFormatType +} from "lexical"; import { cycleSelectionCalloutFormats, formatCodeBlock, insertOrUpdateLink, @@ -27,8 +34,8 @@ function wrapFormatAction(formatAction: (editor: LexicalEditor) => any): Shortcu }; } -function toggleInlineCode(editor: LexicalEditor): boolean { - editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code'); +function toggleInlineFormat(editor: LexicalEditor, format: TextFormatType): boolean { + editor.dispatchCommand(FORMAT_TEXT_COMMAND, format); return true; } @@ -39,8 +46,11 @@ type ShortcutAction = (editor: LexicalEditor, context: EditorUiContext) => boole * We use "meta" as an abstraction for ctrl/cmd depending on platform. */ const baseActionsByKeys: Record = { - 'meta+8': toggleInlineCode, - 'meta+shift+e': toggleInlineCode, + 'meta+8': (e) => toggleInlineFormat(e, 'code'), + 'meta+shift+e': (e) => toggleInlineFormat(e, 'code'), + 'meta+b': (e) => toggleInlineFormat(e, 'bold'), + 'meta+i': (e) => toggleInlineFormat(e, 'italic'), + 'meta+u': (e) => toggleInlineFormat(e, 'underline'), 'meta+o': wrapFormatAction((e) => toggleSelectionAsList(e, 'number')), 'meta+p': wrapFormatAction((e) => toggleSelectionAsList(e, 'bullet')), 'meta+k': (editor, context) => {