From 1c81aab3390843b1f617a0c3ad0fa5a474e2249d Mon Sep 17 00:00:00 2001 From: mattpass Date: Sat, 26 Sep 2020 09:23:54 +0100 Subject: [PATCH] Code tweaks to close tab functionality --- assets/js/icecoder.js | 77 +++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/assets/js/icecoder.js b/assets/js/icecoder.js index 3490146..26fb987 100644 --- a/assets/js/icecoder.js +++ b/assets/js/icecoder.js @@ -4292,69 +4292,80 @@ var ICEcoder = { // Close the tab upon request closeTab: function(closeTabNum, dontSetPV, dontAsk) { - var okToRemove, closeFileName; + let okToRemove, closeFileName; // If we haven't specified, close current tab - if (!closeTabNum) {closeTabNum = this.selectedTab}; + if (!closeTabNum) { + closeTabNum = this.selectedTab; + }; okToRemove = true; // Only confirm if we're OK to ask and... if (!dontAsk && ( - ("/[NEW]" === this.openFiles[closeTabNum-1] + ("/[NEW]" === this.openFiles[closeTabNum - 1] // ...it's a new file that's not empty ? "" !== this.getcMInstance(closeTabNum).getValue() // ...or it's not a new file and it's not saved - : this.savedPoints[closeTabNum-1] != this.getcMInstance(closeTabNum).changeGeneration() + : this.savedPoints[closeTabNum - 1] !== this.getcMInstance(closeTabNum).changeGeneration() ) )) { okToRemove = this.ask(t['You have made...']); } - if (okToRemove) { + if (true === okToRemove) { // Get the filename of tab we're closing - closeFileName = this.openFiles[closeTabNum-1]; + closeFileName = this.openFiles[closeTabNum - 1]; // recursively copy over all tabs & data from the tab to the right, if there is one - for (var i=closeTabNum;i0 ? this.selectedTab-=1 : this.selectedTab = 0; + if (this.selectedTab == closeTabNum) { + 0 < this.openFiles.length ? this.selectedTab -= 1 : this.selectedTab = 0; } // Handle removing a tab from start or end as safely fallback - if (this.openFiles.length>0 && this.selectedTab === 0) {this.selectedTab = 1}; - if (this.openFiles.length>0 && this.selectedTab > this.openFiles.length) {this.selectedTab = this.openFiles.length}; + if (0 < this.openFiles.length && this.selectedTab === 0) { + this.selectedTab = 1; + }; + if (0 < this.openFiles.length && this.selectedTab > this.openFiles.length) { + this.selectedTab = this.openFiles.length; + }; // grey out the view icon - if (this.openFiles.length==0) { - this.fMIconVis('fMView',0.3); + if (0 === this.openFiles.length) { + this.fMIconVis('fMView', 0.3); } else { // Switch the mode & the tab this.switchMode(); this.switchTab(this.selectedTab); } // Highlight the selected tab after splicing the change state out of the array - this.savedPoints.splice(closeTabNum-1,1); - this.savedContents.splice(closeTabNum-1,1); + this.savedPoints.splice(closeTabNum - 1, 1); + this.savedContents.splice(closeTabNum - 1, 1); this.redoTabHighlight(this.selectedTab); // Remove any highlighting from the file manager - this.selectDeselectFile('deselect',this.filesFrame.contentWindow.document.getElementById(closeFileName.replace(/\//g,"|"))); + this.selectDeselectFile( + 'deselect', + this.filesFrame.contentWindow.document.getElementById( + closeFileName.replace(/\//g,"|") + ) + ); if (!dontSetPV) { this.setPreviousFiles(); @@ -4367,17 +4378,19 @@ var ICEcoder = { this.indicateChanges(); } // Lastly, stop it from trying to also switch tab - this.canSwitchTabs=false; + this.canSwitchTabs = false; // and set the widths this.setTabWidths('posOnlyNewTab'); - setTimeout(function(ic) {ic.canSwitchTabs=true;},100,this); + setTimeout(function(ic) { + ic.canSwitchTabs = true; + }, 100, this); }, // Close all tabs closeAllTabs: function() { - if (this.cMInstances.length>0 && this.ask(t['Close all tabs'])) { - for (var i=this.cMInstances.length; i>0; i--) { - this.closeTab(i, i>1? true:false); + if (0 < this.cMInstances.length && this.ask(t['Close all tabs'])) { + for (let i = this.cMInstances.length; 0 < i; i--) { + this.closeTab(i, i > 1 ? true : false); } } // Update the title tag to indicate any changes