mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-07-15 21:31:36 +03:00
Lexical: Updated core inline formats to instead custom built handler
Aligns logic used for shortcut handling, so enables these to work for cyrillic equivilent keyboard keys.
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<string, ShortcutAction> = {
|
||||
'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) => {
|
||||
|
||||
Reference in New Issue
Block a user