diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/App.vue | 40 | ||||
| -rw-r--r-- | src/components/SettingsModal.vue | 4 | ||||
| -rw-r--r-- | src/layout.ts | 26 |
3 files changed, 62 insertions, 8 deletions
diff --git a/src/App.vue b/src/App.vue index a59d4ee..c8149e9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -92,6 +92,7 @@ const defaultUiOpts = { clickHoldDuration: 400, //ms (duration after mousedown when a click-and-hold is recognised) // Other useReducedTree: false, + jumpToSearchedNode: false, }; export default defineComponent({ @@ -397,9 +398,9 @@ export default defineComponent({ return; } // Check if searched node is displayed - let layoutNodeVal = this.layoutMap.get(name); - if (layoutNodeVal != null && !layoutNodeVal.hidden){ - this.setLastFocused(layoutNodeVal); + let targetNode = this.layoutMap.get(name); + if (targetNode != null && !targetNode.hidden){ + this.setLastFocused(targetNode); this.modeRunning = false; return; } @@ -411,14 +412,37 @@ export default defineComponent({ let layoutNode = this.layoutMap.get(ancestorName)!; // If hidden, expand self/ancestor in ancestry-bar if (layoutNode.hidden){ - while (!this.detachedAncestors!.includes(layoutNode)){ - layoutNode = layoutNode.parent!; + let visibleNode = layoutNode; + while (!this.detachedAncestors!.includes(visibleNode)){ + visibleNode = visibleNode.parent!; + } + if (!this.uiOpts.jumpToSearchedNode){ + this.onDetachedAncestorClick(visibleNode!); + setTimeout(() => this.expandToNode(name), this.uiOpts.tileChgDuration); + return; + } else { + LayoutNode.showDownward(visibleNode); } - this.onDetachedAncestorClick(layoutNode!); - setTimeout(() => this.expandToNode(name), this.uiOpts.tileChgDuration); - return; } // Attempt tile-expand + if (this.uiOpts.jumpToSearchedNode){ + // Extend layout tree + let tolNode = this.tolMap.get(name)!; + let nodesToAdd = [name] as string[]; + while (tolNode.parent != layoutNode.name){ + nodesToAdd.push(tolNode.parent!); + tolNode = this.tolMap.get(tolNode.parent!)!; + } + nodesToAdd.reverse(); + layoutNode.addDescendantChain(nodesToAdd, this.tolMap, this.layoutMap); + // Expand-to-view on target-node's parent + targetNode = this.layoutMap.get(name); + this.onLeafClickHeld(targetNode!.parent!); + // + this.setLastFocused(targetNode!); + this.modeRunning = false; + return; + } if (this.overflownRoot){ this.onLeafClickHeld(layoutNode); setTimeout(() => this.expandToNode(name), this.uiOpts.tileChgDuration); diff --git a/src/components/SettingsModal.vue b/src/components/SettingsModal.vue index 4af08c5..e9f76c8 100644 --- a/src/components/SettingsModal.vue +++ b/src/components/SettingsModal.vue @@ -122,6 +122,10 @@ export default defineComponent({ </div> <hr class="border-stone-400"/> <div> + <label> <input type="checkbox" v-model="uiOpts.jumpToSearchedNode"/> Jump to search result</label> + </div> + <hr class="border-stone-400"/> + <div> Tree <ul> <li> diff --git a/src/layout.ts b/src/layout.ts index 7cec2a5..ece1c1a 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -107,6 +107,32 @@ export class LayoutNode { this.sepSweptArea = sepSweptArea; this.empSpc = empSpc; } + // Add descendant nodes, along a sequence from a child to a grandchild, and so on + addDescendantChain(nameChain: string[], tolMap: TolMap, map?: LayoutMap): void { + let layoutNode = this as LayoutNode; + for (let childName of nameChain){ + if (layoutNode.children.length > 0){ + throw new Error('Expected child node without children'); + } + // Add children + let tolNode = tolMap.get(layoutNode.name)!; + layoutNode.children = tolNode.children.map((name: string) => new LayoutNode(name, [])); + layoutNode.children.forEach(node => { + node.parent = layoutNode; + node.depth = layoutNode.depth + 1; + if (map != null){ + map.set(node.name, node); + } + }); + LayoutNode.updateDCounts(layoutNode, layoutNode.children.length); + // Get matching child node + let childNode = layoutNode.children.find(n => n.name == childName); + if (childNode == null){ + throw new Error('Child name not found'); + } + layoutNode = childNode; + } + } // Used to update a LayoutNode tree's dCount fields after adding/removing a node's children static updateDCounts(node: LayoutNode | null, diff: number): void { while (node != null){ |
