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 d3a05ad..d785617 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); @@ -114,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) {