From 682a3dce6bc97d8eea0c344499bf1f7a68d3006e Mon Sep 17 00:00:00 2001 From: "Michal Dziekonski (mdz)" Date: Sun, 15 Sep 2024 11:19:37 +0200 Subject: [PATCH] fix(Editor): Trigger gotoLine only when change is from sidebar (#2012) --- src/components/TheEditor.vue | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/TheEditor.vue b/src/components/TheEditor.vue index 215ed1ccd..dce57ec45 100644 --- a/src/components/TheEditor.vue +++ b/src/components/TheEditor.vue @@ -67,14 +67,15 @@ dense :active="structureActive" :open="structureOpen" - item-key="line" + :item-key="treeviewItemKeyProp" :items="configFileStructure" class="w-100" @update:active="activeChanges"> @@ -188,8 +189,10 @@ export default class TheEditor extends Mixins(BaseMixin) { dialogConfirmChange = false dialogDevices = false fileStructureSidebar = true + treeviewItemKeyProp = 'line' as const structureActive: number[] = [] structureOpen: number[] = [] + structureActiveChangedBySidebar: boolean = false formatFilesize = formatFilesize @@ -424,8 +427,23 @@ export default class TheEditor extends Mixins(BaseMixin) { this.fileStructureSidebar = !this.fileStructureSidebar } - activeChanges(key: any) { - this.editor?.gotoLine(key) + // Relies on event bubbling to flip the flag before treeview active change is handled + activeChangesItemClick() { + this.structureActiveChangedBySidebar = true + } + + activeChanges(activeItems: Array) { + if (!this.structureActiveChangedBySidebar) { + return + } + + this.structureActiveChangedBySidebar = false + + if (!activeItems.length) { + return + } + + this.editor?.gotoLine(activeItems[0]) } lineChanges(line: number) {