]> BookStack Code Mirror - bookstack/commitdiff
Lexical: Fixed issues with recent changes
authorDan Brown <redacted>
Mon, 26 May 2025 18:06:36 +0000 (19:06 +0100)
committerDan Brown <redacted>
Mon, 26 May 2025 18:06:36 +0000 (19:06 +0100)
resources/js/wysiwyg/ui/framework/buttons.ts
resources/js/wysiwyg/utils/nodes.ts

index 0e1cab0f569a7d64a96c7b18669dd6985ae8c514..e12348e814be1cd6df53118663f324ce736849d6 100644 (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');
         }
     }
index 778be5ba6e0a97d32c4b024c3011c228c32806a1..116a3f4e5c01e0a39ee0ed0b564dd325a226b99d 100644 (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);
         }
     }
 
Morty Proxy This is a proxified and sanitized view of the page, visit original site.