mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 14:11:02 +01:00
Adjust number of tabs shown when resizing window.
Improve refresh tabs logic. Fix input not being shown when loaded from a URL
This commit is contained in:
parent
722edcc274
commit
85809efcc0
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,7 +64,10 @@ class InputWaiter {
|
||||
if (this.inputWorker) {
|
||||
this.inputWorker.postMessage({
|
||||
action: "updateMaxTabs",
|
||||
data: this.maxTabs
|
||||
data: {
|
||||
maxTabs: this.maxTabs,
|
||||
activeTab: this.getActiveTab()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user