From fa8111c3881a0e37ef203f2e0ceb9b85748bb27d Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Tue, 24 May 2022 17:37:34 +1000
Subject: Add jump-to-searched-node setting

---
 src/App.vue | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

(limited to 'src/App.vue')

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);
-- 
cgit v1.2.3

