mirror of
https://github.com/facebook/lexical.git
synced 2025-08-06 16:39:33 +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 {useToolbarState} from '../../context/ToolbarContext';
|
||||||
import {sanitizeUrl} from '../../utils/url';
|
import {sanitizeUrl} from '../../utils/url';
|
||||||
|
import {INSERT_INLINE_COMMAND} from '../CommentPlugin';
|
||||||
import {
|
import {
|
||||||
clearFormatting,
|
clearFormatting,
|
||||||
formatBulletList,
|
formatBulletList,
|
||||||
@ -34,6 +35,7 @@ import {
|
|||||||
UpdateFontSizeType,
|
UpdateFontSizeType,
|
||||||
} from '../ToolbarPlugin/utils';
|
} from '../ToolbarPlugin/utils';
|
||||||
import {
|
import {
|
||||||
|
isAddComment,
|
||||||
isCapitalize,
|
isCapitalize,
|
||||||
isCenterAlign,
|
isCenterAlign,
|
||||||
isClearFormatting,
|
isClearFormatting,
|
||||||
@ -158,6 +160,9 @@ export default function ShortcutsPlugin({
|
|||||||
setIsLinkEditMode(!toolbarState.isLink);
|
setIsLinkEditMode(!toolbarState.isLink);
|
||||||
|
|
||||||
editor.dispatchCommand(TOGGLE_LINK_COMMAND, url);
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, url);
|
||||||
|
} else if (isAddComment(event)) {
|
||||||
|
event.preventDefault();
|
||||||
|
editor.dispatchCommand(INSERT_INLINE_COMMAND, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -21,6 +21,7 @@ export const SHORTCUTS = Object.freeze({
|
|||||||
CHECK_LIST: IS_APPLE ? '⌘+Opt+6' : 'Ctrl+Alt+6',
|
CHECK_LIST: IS_APPLE ? '⌘+Opt+6' : 'Ctrl+Alt+6',
|
||||||
CODE_BLOCK: IS_APPLE ? '⌘+Opt+C' : 'Ctrl+Alt+C',
|
CODE_BLOCK: IS_APPLE ? '⌘+Opt+C' : 'Ctrl+Alt+C',
|
||||||
QUOTE: IS_APPLE ? '⌘+Opt+Q' : 'Ctrl+Alt+Q',
|
QUOTE: IS_APPLE ? '⌘+Opt+Q' : 'Ctrl+Alt+Q',
|
||||||
|
ADD_COMMENT: IS_APPLE ? '⌘+Opt+M' : 'Ctrl+Alt+M',
|
||||||
|
|
||||||
// (Ctrl|⌘) + Shift + <key> shortcuts
|
// (Ctrl|⌘) + Shift + <key> shortcuts
|
||||||
INCREASE_FONT_SIZE: IS_APPLE ? '⌘+Shift+.' : 'Ctrl+Shift+.',
|
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)
|
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