Skip to content

Commit 3847944

Browse files
authored
fix: Fix handle activate editor (openscd#1651)
1 parent 70397a9 commit 3847944

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

packages/openscd/src/addons/Layout.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ export class OscdLayout extends LitElement {
7171
@property({ type: String }) docName = '';
7272
/** Index of the last [[`EditorAction`]] applied. */
7373
@property({ type: Number }) editCount = -1;
74-
/** The currently active editor tab. */
75-
@property({ type: Number }) activeTab = 0;
7674

7775
/** The plugins to render the layout. */
7876
@property({ type: Array }) plugins: Plugin[] = [];
@@ -490,22 +488,13 @@ export class OscdLayout extends LitElement {
490488
this.activeEditor = e.detail.editor
491489
}
492490

493-
private handleActivatedEditorTabByUser(e: CustomEvent): void {
494-
const tabIndex = e.detail.index;
495-
this.activateTab(tabIndex);
496-
}
497-
498491
private handleActivateEditorByEvent(e: CustomEvent<{name: string, src: string}>): void {
499492
const {name, src} = e.detail;
500493
const editors = this.calcActiveEditors()
501-
const wantedEditorIndex = editors.findIndex(editor => editor.name === name || editor.src === src)
502-
if(wantedEditorIndex < 0){ return; } // TODO: log error
503-
504-
this.activateTab(wantedEditorIndex);
505-
}
494+
const wantedEditor = editors.find(editor => editor.name === name || editor.src === src)
495+
if(!wantedEditor){ return; } // TODO: log error
506496

507-
private activateTab(index: number){
508-
this.activeTab = index;
497+
this.activeEditor = wantedEditor;
509498
}
510499

511500
private handleRunMenuByEvent(e: CustomEvent<{name: string}>): void {

packages/openscd/src/addons/menu-tabs/menu-tabs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export class OscdMenuTabs extends LitElement {
2727
@property({ type: Object }) get activeEditor() { return this._activeEditor; }
2828
set activeEditor(editor: Plugin | undefined) {
2929
this._activeEditor = editor;
30-
this.activeTabIndex = this.editors.indexOf(this.activeEditor || this.editors[0]);
30+
const editorIndex = this.editors.findIndex(e => e.name === editor?.name && e.src === editor?.src);
31+
this.activeTabIndex = editorIndex > -1 ? editorIndex : 0;
3132
this.requestUpdate();
3233
};
3334

0 commit comments

Comments
 (0)