Fix: make sure Edit buttons work even for Lua expressions and code

widgets whose bodies appear multiple times in the same page (previously
always jumped to first).
This commit is contained in:
Zef Hemel
2026-03-12 14:13:18 +01:00
parent 1f7a4d7d66
commit dbcef9e8aa
5 changed files with 33 additions and 24 deletions
+4 -5
View File
@@ -10,8 +10,6 @@ export class IFrameWidget extends WidgetType {
iframe?: HTMLIFrameElement;
constructor(
readonly from: number,
readonly to: number,
readonly client: Client,
readonly bodyText: string,
readonly codeWidgetCallback: CodeWidgetCallback,
@@ -28,20 +26,21 @@ export class IFrameWidget extends WidgetType {
}
toDOM(): HTMLElement {
const from = this.from;
const iframe = createWidgetSandboxIFrame(
this.client,
this.bodyText,
this.codeWidgetCallback(this.bodyText, this.client.currentName()),
(message) => {
switch (message.type) {
case "blur":
case "blur": {
const pos = this.client.editorView.posAtDOM(iframe, 0);
this.client.editorView.dispatch({
selection: { anchor: from },
selection: { anchor: pos },
});
this.client.focus();
break;
}
case "reload":
void this.codeWidgetCallback(
this.bodyText,