From ae008e523c1db6605b0330b2afd5a957e4073e40 Mon Sep 17 00:00:00 2001 From: mattpass Date: Sun, 25 Jul 2021 16:14:36 +0100 Subject: [PATCH] Better handing of find and gotoline when 0 docs open --- assets/js/icecoder.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/assets/js/icecoder.js b/assets/js/icecoder.js index 15c4fe9..b5d3d36 100644 --- a/assets/js/icecoder.js +++ b/assets/js/icecoder.js @@ -1180,6 +1180,11 @@ var ICEcoder = { goToLine: function(lineNo, charNo, noFocus) { let thisCM, hiddenLines, tgtLineNo; + // Return early if trying to find line and no files open + if (0 === this.openFiles.length) { + return false; + } + lineNo = lineNo ? lineNo - 1 : get('goToLineNo').value - 1; charNo = charNo ? charNo : 0; @@ -2921,9 +2926,7 @@ var ICEcoder = { ("" === balancedInfo['remainder'].replace(/\[\]\{\}\(\)/g, "")) || "" === find.replace(/\^|\$|\.\*/g, "") )) { - results.innerHTML = "No results"; - this.content.contentWindow.document.getElementById('resultsBar').innerHTML = ""; - this.content.contentWindow.document.getElementById('resultsBar').style.display = "none"; + this.clearResultsDisplays(); get('find').style.background = "#800"; return false; } else { @@ -3025,9 +3028,7 @@ var ICEcoder = { return true; } else { - results.innerHTML = "No results"; - this.content.contentWindow.document.getElementById('resultsBar').innerHTML = ""; - this.content.contentWindow.document.getElementById('resultsBar').style.display = "none"; + this.clearResultsDisplays(); return false; } @@ -3067,13 +3068,17 @@ var ICEcoder = { '" id="multipleResultsIFrame" style="width: 700px; height: 500px">'; // We have nothing to search for, blank it all out } else { - results.innerHTML = "No results"; - this.content.contentWindow.document.getElementById('resultsBar').innerHTML = ""; - this.content.contentWindow.document.getElementById('resultsBar').style.display = "none"; + this.clearResultsDisplays(); } } }, + clearResultsDisplays: function() { + results.innerHTML = this.openFiles.length > 0 ? "No results" : ""; + this.content.contentWindow.document.getElementById('resultsBar').innerHTML = ""; + this.content.contentWindow.document.getElementById('resultsBar').style.display = "none"; + }, + findInCMContent: function(thisCM, rExp, selectNext) { let avgBlockH, addPadding, rBlocks, haveMatch, rExpMatch0String, rBlockTop, lastRBlockTop; @@ -4589,6 +4594,8 @@ var ICEcoder = { // Grey out the view icon if (0 === this.openFiles.length) { this.fMIconVis('fMView', 0.3); + // Also clear any find results + this.clearResultsDisplays(); } else { // Switch the mode & the tab this.switchMode();