Skip to content

Commit b2f8ae5

Browse files
author
valtih1978
committed
Using timeout to clear search on popup hide (issue 34)
#34
1 parent 327b405 commit b2f8ae5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/content/content.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ module Content {
4949
setTimeout(function() {fn.call(null, data);}, timeout);
5050
}
5151

52+
var cleanupMonitor = null; function startCleanupMonitor() {
53+
cleanupMonitor = setTimeout(function() {clear()}, 500)
54+
} ; function stopCleanupMonitor(afterStop) { if (cleanupMonitor != null)
55+
{ clearTimeout(cleanupMonitor); afterStop();}
56+
}
57+
5258
chrome.runtime.onMessage.addListener(
5359
function(request, sender, sendResponse) {
5460
Log.debug("Received command " + request.command);
@@ -60,6 +66,7 @@ module Content {
6066
flags = "gi";
6167
}
6268
clear();
69+
startCleanupMonitor();
6370
infoSpan.add();
6471
infoSpan.setText("Searching...");
6572
var re = new RegExp(request.regexp, flags);
@@ -73,6 +80,8 @@ module Content {
7380
move(false);
7481
} else if (request.command == "next") {
7582
move(true);
83+
} else if (request.command == "ping") {
84+
stopCleanupMonitor(() => startCleanupMonitor()); // restart the monitor
7685
} else {
7786
Log.debug("Invalid command");
7887
}
@@ -177,6 +186,7 @@ module Content {
177186
// Remove all matches
178187
function clear(): void {
179188
infoSpan.setText("Clearing...");
189+
stopCleanupMonitor(() => cleanupMonitor = null)
180190
setTimeout(function() {
181191
cur = 0;
182192
for (var i = 0; i < marks.length; i++) {

src/popup/popup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ module Popup {
111111
queryInput.addEventListener("keydown", queryInputKeyDown);
112112
queryInput.addEventListener("input", queryInputInput);
113113
caseInsensitiveCheckbox.onclick = checkboxClick;
114+
115+
setInterval(function(){Utils.sendCommand("ping")}, 300)
114116
}
115117

116118
function restoreState(tabId: number, tabStates: TabStateManager) {

0 commit comments

Comments
 (0)