Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Editor): Trigger gotoLine only when change is from sidebar #2012

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/components/TheEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@
dense
:active="structureActive"
:open="structureOpen"
item-key="line"
:item-key="treeviewItemKeyProp"
:items="configFileStructure"
class="w-100"
@update:active="activeChanges">
<template #label="{ item }">
<div
class="cursor-pointer _structure-sidebar-item"
:class="item.type == 'item' ? 'ͼp' : 'ͼt'">
:class="item.type == 'item' ? 'ͼp' : 'ͼt'"
@click="activeChangesItemClick">
{{ item.name }}
</div>
</template>
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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<ConfigFileSection[typeof this.treeviewItemKeyProp]>) {
if (!this.structureActiveChangedBySidebar) {
return
}

this.structureActiveChangedBySidebar = false

if (!activeItems.length) {
return
}

this.editor?.gotoLine(activeItems[0])
}

lineChanges(line: number) {
Expand Down
Loading