1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Started adding editor shortcuts

This commit is contained in:
Dan Brown
2024-08-20 13:07:33 +01:00
parent 111a313d51
commit aa1fac62d5
13 changed files with 223 additions and 50 deletions

View File

@ -8,7 +8,7 @@ import {
$setSelection,
BaseSelection,
ElementFormatType,
ElementNode,
ElementNode, LexicalEditor,
LexicalNode,
TextFormatType
} from "lexical";
@ -17,6 +17,17 @@ import {LexicalElementNodeCreator, LexicalNodeMatcher} from "../nodes";
import {$setBlocksType} from "@lexical/selection";
import {$getParentOfType} from "./nodes";
import {$createCustomParagraphNode} from "../nodes/custom-paragraph";
const lastSelectionByEditor = new WeakMap<LexicalEditor, BaseSelection|null>;
export function getLastSelection(editor: LexicalEditor): BaseSelection|null {
return lastSelectionByEditor.get(editor) || null;
}
export function setLastSelection(editor: LexicalEditor, selection: BaseSelection|null): void {
lastSelectionByEditor.set(editor, selection);
}
export function $selectionContainsNodeType(selection: BaseSelection | null, matcher: LexicalNodeMatcher): boolean {
return $getNodeFromSelection(selection, matcher) !== null;
@ -59,7 +70,7 @@ export function $toggleSelectionBlockNodeType(matcher: LexicalNodeMatcher, creat
const selection = $getSelection();
const blockElement = selection ? $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]) : null;
if (selection && matcher(blockElement)) {
$setBlocksType(selection, $createParagraphNode);
$setBlocksType(selection, $createCustomParagraphNode);
} else {
$setBlocksType(selection, creator);
}