From d9ea52522ea577e960ff978e186fd7c5226535f5 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 26 May 2025 19:06:36 +0100 Subject: [PATCH] Lexical: Fixed issues with recent changes --- resources/js/wysiwyg/ui/framework/buttons.ts | 10 ++++++++-- resources/js/wysiwyg/utils/nodes.ts | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/resources/js/wysiwyg/ui/framework/buttons.ts b/resources/js/wysiwyg/ui/framework/buttons.ts index 0e1cab0f5..e12348e81 100644 --- a/resources/js/wysiwyg/ui/framework/buttons.ts +++ b/resources/js/wysiwyg/ui/framework/buttons.ts @@ -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; 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'); } } diff --git a/resources/js/wysiwyg/utils/nodes.ts b/resources/js/wysiwyg/utils/nodes.ts index 778be5ba6..116a3f4e5 100644 --- a/resources/js/wysiwyg/utils/nodes.ts +++ b/resources/js/wysiwyg/utils/nodes.ts @@ -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); } }