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

@ -15,7 +15,6 @@ export type EditorUiContext = {
scrollDOM: HTMLElement; // DOM element which is the main content scroll container
translate: (text: string) => string; // Translate function
manager: EditorUIManager; // UI Manager instance for this editor
lastSelection: BaseSelection|null; // The last tracked selection made by the user
options: Record<string, any>; // General user options which may be used by sub elements
};

View File

@ -5,6 +5,7 @@ import {$getSelection, BaseSelection, COMMAND_PRIORITY_LOW, LexicalEditor, SELEC
import {DecoratorListener} from "lexical/LexicalEditor";
import type {NodeKey} from "lexical/LexicalNode";
import {EditorContextToolbar, EditorContextToolbarDefinition} from "./toolbars";
import {getLastSelection, setLastSelection} from "../../utils/selection";
export type SelectionChangeHandler = (selection: BaseSelection|null) => void;
@ -108,8 +109,7 @@ export class EditorUIManager {
}
protected triggerStateUpdate(update: EditorUiStateUpdate): void {
const context = this.getContext();
context.lastSelection = update.selection;
setLastSelection(update.editor, update.selection);
this.toolbar?.updateState(update);
this.updateContextToolbars(update);
for (const toolbar of this.activeContextToolbars) {
@ -119,9 +119,10 @@ export class EditorUIManager {
}
triggerStateRefresh(): void {
const editor = this.getContext().editor;
this.triggerStateUpdate({
editor: this.getContext().editor,
selection: this.getContext().lastSelection,
editor,
selection: getLastSelection(editor),
});
}