From 85809efcc0b1a613baabf611c810e512019cc159 Mon Sep 17 00:00:00 2001 From: j433866 Date: Wed, 29 May 2019 13:25:12 +0100 Subject: [PATCH] Adjust number of tabs shown when resizing window. Improve refresh tabs logic. Fix input not being shown when loaded from a URL --- src/web/App.mjs | 12 ++++++++++++ src/web/InputWaiter.mjs | 5 ++++- src/web/InputWorker.mjs | 40 +++++++++++++++++++++------------------- src/web/OutputWaiter.mjs | 31 ++++++++++++------------------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/web/App.mjs b/src/web/App.mjs index 5735dca7..055401e2 100755 --- a/src/web/App.mjs +++ b/src/web/App.mjs @@ -200,6 +200,14 @@ class App { let inputNum = this.manager.input.getActiveTab(); if (inputNum === -1) inputNum = 1; this.manager.input.updateInputValue(inputNum, input); + + this.manager.input.inputWorker.postMessage({ + action: "setInput", + data: { + inputNum: inputNum, + silent: true + } + }); } @@ -264,6 +272,8 @@ class App { expandToMin: false, onDrag: function() { this.manager.recipe.adjustWidth(); + this.manager.input.calcMaxTabs(); + this.manager.output.calcMaxTabs(); }.bind(this) }); @@ -536,6 +546,8 @@ class App { this.columnSplitter.setSizes([20, 30, 50]); this.ioSplitter.setSizes([50, 50]); this.manager.recipe.adjustWidth(); + this.manager.input.calcMaxTabs(); + this.manager.output.calcMaxTabs(); } diff --git a/src/web/InputWaiter.mjs b/src/web/InputWaiter.mjs index 70358416..b27bcf76 100644 --- a/src/web/InputWaiter.mjs +++ b/src/web/InputWaiter.mjs @@ -64,7 +64,10 @@ class InputWaiter { if (this.inputWorker) { this.inputWorker.postMessage({ action: "updateMaxTabs", - data: this.maxTabs + data: { + maxTabs: this.maxTabs, + activeTab: this.getActiveTab() + } }); } } diff --git a/src/web/InputWorker.mjs b/src/web/InputWorker.mjs index bf9cb340..9cbd248e 100644 --- a/src/web/InputWorker.mjs +++ b/src/web/InputWorker.mjs @@ -43,7 +43,7 @@ self.addEventListener("message", function(e) { self.maxWorkers = r.data; break; case "updateMaxTabs": - self.maxTabs = r.data; + self.updateMaxTabs(r.data.maxTabs, r.data.activeTab); break; case "updateInputValue": self.updateInputValue(r.data); @@ -280,15 +280,9 @@ self.getInputProgress = function(inputNum) { * @returns {number} */ self.getLargestInputNum = function() { - let largest = 0; const inputNums = Object.keys(self.inputs); - for (let i = 0; i < inputNums.length; i++) { - const num = parseInt(inputNums[i], 10); - if (num > largest) { - largest = num; - } - } - return largest; + if (inputNums.length === 0) return -1; + return Math.max(...inputNums); }; /** @@ -297,15 +291,9 @@ self.getLargestInputNum = function() { * @returns {number} */ self.getSmallestInputNum = function() { - let smallest = self.getLargestInputNum(); const inputNums = Object.keys(self.inputs); - for (let i = 0; i < inputNums.length; i++) { - const num = parseInt(inputNums[i], 10); - if (num < smallest) { - smallest = num; - } - } - return smallest; + if (inputNums.length === 0) return -1; + return Math.min(...inputNums); }; /** @@ -315,8 +303,9 @@ self.getSmallestInputNum = function() { * @returns {number} */ self.getPreviousInputNum = function(inputNum) { - let num = -1; const inputNums = Object.keys(self.inputs); + if (inputNums.length === 0) return -1; + let num = Math.min(...inputNums); for (let i = 0; i < inputNums.length; i++) { const iNum = parseInt(inputNums[i], 10); if (iNum < inputNum) { @@ -335,8 +324,8 @@ self.getPreviousInputNum = function(inputNum) { * @returns {number} */ self.getNextInputNum = function(inputNum) { - let num = self.getLargestInputNum(); const inputNums = Object.keys(self.inputs); + let num = Math.max(...inputNums); for (let i = 0; i < inputNums.length; i++) { const iNum = parseInt(inputNums[i], 10); if (iNum > inputNum) { @@ -884,6 +873,19 @@ self.changeTabLeft = function(inputNum, tabNums) { } }; +/** + * Updates the maximum number of tabs, and refreshes them if it changes + * + * @param {number} maxTabs - The new max number of tabs + * @param {number} activeTab - The currently selected tab + */ +self.updateMaxTabs = function(maxTabs, activeTab) { + if (self.maxTabs !== maxTabs) { + self.maxTabs = maxTabs; + self.refreshTabs(activeTab, "right"); + } +}; + /** * Search the inputs for any that match the filters provided, * posting the results back to the inputWaiter diff --git a/src/web/OutputWaiter.mjs b/src/web/OutputWaiter.mjs index 92387921..03510b08 100755 --- a/src/web/OutputWaiter.mjs +++ b/src/web/OutputWaiter.mjs @@ -37,7 +37,10 @@ class OutputWaiter { */ calcMaxTabs() { const numTabs = Math.floor((document.getElementById("IO").offsetWidth - 75) / 120); - this.maxTabs = numTabs; + if (numTabs !== this.maxTabs) { + this.maxTabs = numTabs; + this.refreshTabs(this.getActiveTab()); + } } /** @@ -802,15 +805,9 @@ class OutputWaiter { * @returns {number} */ getLargestInputNum() { - let largest = 0; const inputNums = Object.keys(this.outputs); - for (let i = 0; i < inputNums.length; i++) { - const iNum = parseInt(inputNums[i], 10); - if (iNum > largest) { - largest = iNum; - } - } - return largest; + if (inputNums.length === 0) return -1; + return Math.max(...inputNums); } /** @@ -819,15 +816,9 @@ class OutputWaiter { * @returns {number} */ getSmallestInputNum() { - let smallest = this.getLargestInputNum(); const inputNums = Object.keys(this.outputs); - for (let i = 0; i < inputNums.length; i++) { - const iNum = parseInt(inputNums[i], 10); - if (iNum < smallest) { - smallest = iNum; - } - } - return smallest; + if (inputNums.length === 0) return -1; + return Math.min(...inputNums); } /** @@ -837,8 +828,9 @@ class OutputWaiter { * @returns {number} */ getPreviousInputNum(inputNum) { - let num = this.getSmallestInputNum(); const inputNums = Object.keys(this.outputs); + if (inputNums.length === 0) return -1; + let num = Math.min(...inputNums); for (let i = 0; i < inputNums.length; i++) { const iNum = parseInt(inputNums[i], 10); if (iNum < inputNum) { @@ -857,8 +849,9 @@ class OutputWaiter { * @returns {number} */ getNextInputNum(inputNum) { - let num = this.getLargestInputNum(); const inputNums = Object.keys(this.outputs); + if (inputNums.length === 0) return -1; + let num = Math.max(...inputNums); for (let i = 0; i < inputNums.length; i++) { const iNum = parseInt(inputNums[i], 10); if (iNum > inputNum) {