mirror of
https://github.com/facebook/lexical.git
synced 2025-05-17 06:59:17 +08:00
[lexical-playground] Feature: Add keyboard shortcut for comments (#7464)
This commit is contained in:
@ -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;
|
||||
|
@ -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 + <key> 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)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user