From 327b405371e716765df01e638cfd0c4db1f9eaca Mon Sep 17 00:00:00 2001 From: valtih1978 Date: Wed, 13 Jul 2016 09:27:29 +0300 Subject: [PATCH 1/2] Undo clear on Esc. It makes no sense anyway (issue 34) --- src/popup/popup.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/popup/popup.ts b/src/popup/popup.ts index d3a05ad..c031b46 100644 --- a/src/popup/popup.ts +++ b/src/popup/popup.ts @@ -78,20 +78,20 @@ module Popup { } else { search(id, tabStates); } - } else if (event.keyCode == 27) { - Log.info("Esc pressed"); - setSearching(id, false, tabStates); - Utils.sendCommand("clear"); } } - var queryInputInput = function() { - tabStates.set(id, "query", queryInput.value); - + function clear() { if (tabStates.isSearching(id)) { setSearching(id, false, tabStates); Utils.sendCommand("clear"); } + } + + var queryInputInput = function() { + tabStates.set(id, "query", queryInput.value); + + clear(); // Remove the invalid class if it's there queryInput.className = ''; @@ -103,10 +103,7 @@ module Popup { Log.info("Set checkbox state to " + caseInsensitiveCheckbox.checked); tabStates.set(id, "caseInsensitive", caseInsensitiveCheckbox.checked); - if (tabStates.isSearching(id)) { - setSearching(id, false, tabStates); - Utils.sendCommand("clear"); - } + clear(); } prevButton.addEventListener("click", prevButtonClick); From b2f8ae52b98774915565dee6fc05516c8866deeb Mon Sep 17 00:00:00 2001 From: valtih1978 Date: Tue, 12 Jul 2016 23:04:45 +0300 Subject: [PATCH 2/2] Using timeout to clear search on popup hide (issue 34) https://github.com/gsingh93/regex-search/issues/34 --- src/content/content.ts | 10 ++++++++++ src/popup/popup.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/content/content.ts b/src/content/content.ts index ab2ed97..147264f 100644 --- a/src/content/content.ts +++ b/src/content/content.ts @@ -49,6 +49,12 @@ module Content { setTimeout(function() {fn.call(null, data);}, timeout); } + var cleanupMonitor = null; function startCleanupMonitor() { + cleanupMonitor = setTimeout(function() {clear()}, 500) + } ; function stopCleanupMonitor(afterStop) { if (cleanupMonitor != null) + { clearTimeout(cleanupMonitor); afterStop();} + } + chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { Log.debug("Received command " + request.command); @@ -60,6 +66,7 @@ module Content { flags = "gi"; } clear(); + startCleanupMonitor(); infoSpan.add(); infoSpan.setText("Searching..."); var re = new RegExp(request.regexp, flags); @@ -73,6 +80,8 @@ module Content { move(false); } else if (request.command == "next") { move(true); + } else if (request.command == "ping") { + stopCleanupMonitor(() => startCleanupMonitor()); // restart the monitor } else { Log.debug("Invalid command"); } @@ -177,6 +186,7 @@ module Content { // Remove all matches function clear(): void { infoSpan.setText("Clearing..."); + stopCleanupMonitor(() => cleanupMonitor = null) setTimeout(function() { cur = 0; for (var i = 0; i < marks.length; i++) { diff --git a/src/popup/popup.ts b/src/popup/popup.ts index c031b46..d785617 100644 --- a/src/popup/popup.ts +++ b/src/popup/popup.ts @@ -111,6 +111,8 @@ module Popup { queryInput.addEventListener("keydown", queryInputKeyDown); queryInput.addEventListener("input", queryInputInput); caseInsensitiveCheckbox.onclick = checkboxClick; + + setInterval(function(){Utils.sendCommand("ping")}, 300) } function restoreState(tabId: number, tabStates: TabStateManager) {