diff --git a/packages/lexical-playground/src/plugins/ShortcutsPlugin/index.tsx b/packages/lexical-playground/src/plugins/ShortcutsPlugin/index.tsx index eff896fca..dfb93ba30 100644 --- a/packages/lexical-playground/src/plugins/ShortcutsPlugin/index.tsx +++ b/packages/lexical-playground/src/plugins/ShortcutsPlugin/index.tsx @@ -21,6 +21,7 @@ import {Dispatch, useEffect} from 'react'; import {useToolbarState} from '../../context/ToolbarContext'; import {sanitizeUrl} from '../../utils/url'; +import {INSERT_INLINE_COMMAND} from '../CommentPlugin'; import { clearFormatting, formatBulletList, @@ -34,6 +35,7 @@ import { UpdateFontSizeType, } from '../ToolbarPlugin/utils'; import { + isAddComment, isCapitalize, isCenterAlign, isClearFormatting, @@ -158,6 +160,9 @@ export default function ShortcutsPlugin({ setIsLinkEditMode(!toolbarState.isLink); editor.dispatchCommand(TOGGLE_LINK_COMMAND, url); + } else if (isAddComment(event)) { + event.preventDefault(); + editor.dispatchCommand(INSERT_INLINE_COMMAND, undefined); } return false; diff --git a/packages/lexical-playground/src/plugins/ShortcutsPlugin/shortcuts.ts b/packages/lexical-playground/src/plugins/ShortcutsPlugin/shortcuts.ts index 381d3de54..fe1bfd5da 100644 --- a/packages/lexical-playground/src/plugins/ShortcutsPlugin/shortcuts.ts +++ b/packages/lexical-playground/src/plugins/ShortcutsPlugin/shortcuts.ts @@ -21,6 +21,7 @@ export const SHORTCUTS = Object.freeze({ CHECK_LIST: IS_APPLE ? '⌘+Opt+6' : 'Ctrl+Alt+6', CODE_BLOCK: IS_APPLE ? '⌘+Opt+C' : 'Ctrl+Alt+C', QUOTE: IS_APPLE ? '⌘+Opt+Q' : 'Ctrl+Alt+Q', + ADD_COMMENT: IS_APPLE ? '⌘+Opt+M' : 'Ctrl+Alt+M', // (Ctrl|⌘) + Shift + shortcuts INCREASE_FONT_SIZE: IS_APPLE ? '⌘+Shift+.' : 'Ctrl+Shift+.', @@ -256,3 +257,10 @@ export function isInsertLink(event: KeyboardEvent): boolean { code === 'KeyK' && !shiftKey && !altKey && controlOrMeta(metaKey, ctrlKey) ); } + +export function isAddComment(event: KeyboardEvent): boolean { + const {code, shiftKey, altKey, metaKey, ctrlKey} = event; + return ( + code === 'KeyM' && !shiftKey && altKey && controlOrMeta(metaKey, ctrlKey) + ); +}