Skip to content

Commit d9ea525

Browse files
committed
Lexical: Fixed issues with recent changes
1 parent 2e718c1 commit d9ea525

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

resources/js/wysiwyg/ui/framework/buttons.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface EditorButtonDefinition extends EditorBasicButtonDefinition {
1515
* This can return false to indicate that the completion of the action should
1616
* NOT be communicated to parent UI elements, which is what occurs by default.
1717
*/
18-
action: (context: EditorUiContext, button: EditorButton) => void|false;
18+
action: (context: EditorUiContext, button: EditorButton) => void|false|Promise<void|boolean>;
1919
isActive: (selection: BaseSelection|null, context: EditorUiContext) => boolean;
2020
isDisabled?: (selection: BaseSelection|null, context: EditorUiContext) => boolean;
2121
setup?: (context: EditorUiContext, button: EditorButton) => void;
@@ -84,7 +84,13 @@ export class EditorButton extends EditorUiElement {
8484

8585
protected onClick() {
8686
const result = this.definition.action(this.getContext(), this);
87-
if (result !== false) {
87+
if (result instanceof Promise) {
88+
result.then(result => {
89+
if (result === false) {
90+
this.emitEvent('button-action');
91+
}
92+
});
93+
} else if (result !== false) {
8894
this.emitEvent('button-action');
8995
}
9096
}

resources/js/wysiwyg/utils/nodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ export function $selectOrCreateAdjacent(node: LexicalNode, after: boolean): Rang
125125
if (!target) {
126126
target = $createParagraphNode();
127127
if (after) {
128-
node.insertAfter(target)
128+
nearestBlock.insertAfter(target)
129129
} else {
130-
node.insertBefore(target);
130+
nearestBlock.insertBefore(target);
131131
}
132132
}
133133

0 commit comments

Comments
 (0)