From f1f16687492102ccf8de3eaeda682c154518c321 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Sat, 9 Jul 2022 15:00:34 +1000
Subject: Fix jump-to-overflowing after startup producing collapsed node

Turns out the closing of the tutorial-pane triggered a
relayoutWithCollapse() which collapsed the node.
---
 src/App.vue | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index 784b15d..6dc5440 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -544,11 +544,15 @@ export default defineComponent({
 				// Expand-to-view on target-node's parent
 				targetNode = this.layoutMap.get(name);
 				if (targetNode!.parent != this.activeRoot){
-					await this.onLeafClickHeld(targetNode!.parent!, true);
+					// Hide ancestors
+					LayoutNode.hideUpward(targetNode.parent, this.layoutMap);
+					this.activeRoot = targetNode.parent;
+					await this.onNonleafClick(this.activeRoot, true);
+					await this.onLeafClick(this.activeRoot, true);
 				} else {
-					await this.onLeafClick(targetNode!.parent!, true);
+					await this.onLeafClick(this.activeRoot, true);
 				}
-				setTimeout(() => this.setLastFocused(targetNode!), this.uiOpts.transitionDuration);
+				setTimeout(() => this.setLastFocused(this.layoutMap.get(name)), this.uiOpts.transitionDuration);
 				this.modeRunning = null;
 				return;
 			}
@@ -741,7 +745,7 @@ export default defineComponent({
 			this.tutWelcome = false;
 			this.uiOpts.disabledActions.clear();
 			this.updateAreaDims();
-			this.relayoutWithCollapse();
+			this.relayoutWithCollapse(true, true);
 		},
 		onTutStageChg(triggerAction: Action | null): void {
 			this.tutWelcome = false;
@@ -949,11 +953,17 @@ export default defineComponent({
 			return opts;
 		},
 		// For relayout
-		relayoutWithCollapse(secondPass = true): boolean {
+		relayoutWithCollapse(secondPass = true, keepOverflow = false): boolean {
+			let success: boolean;
 			if (this.overflownRoot){
+				if (keepOverflow){
+					success = tryLayout(this.activeRoot, this.tileAreaDims,
+						{...this.lytOpts, layoutType: 'sqr-overflow'}, {layoutMap: this.layoutMap});
+					return success;
+				}
 				this.overflownRoot = false;
 			}
-			let success = tryLayout(this.activeRoot, this.tileAreaDims, this.lytOpts,
+			success = tryLayout(this.activeRoot, this.tileAreaDims, this.lytOpts,
 				{allowCollapse: true, layoutMap: this.layoutMap});
 			if (secondPass){
 				// Relayout again, which can help allocate remaining tiles 'evenly'
-- 
cgit v1.2.3

