From e4da21fd63d24a40e2887c8ac3c88b61fcae31bd Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Fri, 27 May 2022 23:12:09 +1000
Subject: Make search-suggestion-requests and resize-handling
 initially-immediate

---
 src/App.vue | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

(limited to 'src/App.vue')

diff --git a/src/App.vue b/src/App.vue
index a27cc08..0801124 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -127,7 +127,8 @@ export default defineComponent({
 			// For layout and resize-handling
 			mainAreaDims: [0, 0] as [number, number],
 			tileAreaDims: [0, 0] as [number, number],
-			pendingResizeHdlr: 0, // Set to a setTimeout() value
+			lastResizeHdlrTime: 0, // Used to throttle resize handling
+			pendingResizeHdlr: 0, // Set via setTimeout() for a non-initial resize event
 			// Other
 			justInitialised: false,
 			excessTolNodeThreshold: 1000, // Threshold where excess tolMap entries are removed (done on tile collapse)
@@ -590,14 +591,28 @@ export default defineComponent({
 		},
 		// For other events
 		onResize(){
+			// Handle event, delaying/ignoring if this was recently done
 			if (this.pendingResizeHdlr == 0){
-				this.pendingResizeHdlr = setTimeout(() => {
+				const resizeDelay = 100;
+				let handleResize = () => {
 					this.uiOpts.scrollGap = getScrollBarWidth();
-					this.updateAreaDims().then(() => {
-						this.relayoutWithCollapse();
-						this.pendingResizeHdlr = 0;
+					return this.updateAreaDims().then(() => this.relayoutWithCollapse());
+				};
+				let currentTime = new Date().getTime();
+				if (currentTime - this.lastResizeHdlrTime > resizeDelay){
+					this.lastResizeHdlrTime = currentTime;
+					handleResize().then(() => {
+						this.lastResizeHdlrTime = new Date().getTime();
 					});
-				}, 100);
+				} else {
+					let remainingDelay = resizeDelay - (currentTime - this.lastResizeHdlrTime);
+					this.pendingResizeHdlr = setTimeout(() => {
+						this.pendingResizeHdlr = 0;
+						handleResize().then(() => {
+							this.lastResizeHdlrTime = new Date().getTime();
+						});
+					}, remainingDelay);
+				}
 			}
 		},
 		onKeyUp(evt: KeyboardEvent){
-- 
cgit v1.2.3

