Lexical: Fixed issues with recent changes

This commit is contained in:
Dan Brown 2025-05-26 19:06:36 +01:00
parent 2e718c12e1
commit d9ea52522e
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 10 additions and 4 deletions

View File

@ -15,7 +15,7 @@ export interface EditorButtonDefinition extends EditorBasicButtonDefinition {
* This can return false to indicate that the completion of the action should
* NOT be communicated to parent UI elements, which is what occurs by default.
*/
action: (context: EditorUiContext, button: EditorButton) => void|false;
action: (context: EditorUiContext, button: EditorButton) => void|false|Promise<void|boolean>;
isActive: (selection: BaseSelection|null, context: EditorUiContext) => boolean;
isDisabled?: (selection: BaseSelection|null, context: EditorUiContext) => boolean;
setup?: (context: EditorUiContext, button: EditorButton) => void;
@ -84,7 +84,13 @@ export class EditorButton extends EditorUiElement {
protected onClick() {
const result = this.definition.action(this.getContext(), this);
if (result !== false) {
if (result instanceof Promise) {
result.then(result => {
if (result === false) {
this.emitEvent('button-action');
}
});
} else if (result !== false) {
this.emitEvent('button-action');
}
}

View File

@ -125,9 +125,9 @@ export function $selectOrCreateAdjacent(node: LexicalNode, after: boolean): Rang
if (!target) {
target = $createParagraphNode();
if (after) {
node.insertAfter(target)
nearestBlock.insertAfter(target)
} else {
node.insertBefore(target);
nearestBlock.insertBefore(target);
}
}