1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 18:42:27 +01:00

Allow C-c to interrupt search highlighting

This commit is contained in:
Kris Maglione
2008-10-07 14:25:18 +00:00
parent 73a2d510a7
commit 45ad9f0c8b
4 changed files with 20 additions and 10 deletions

View File

@@ -537,10 +537,7 @@ liberator.Events = function () //{{{
function waitForPageLoaded() function waitForPageLoaded()
{ {
liberator.dump("start waiting in loaded state: " + liberator.buffer.loaded + "\n"); liberator.dump("start waiting in loaded state: " + liberator.buffer.loaded + "\n");
var mainThread = Components.classes["@mozilla.org/thread-manager;1"] liberator.threadyield(true); // clear queue
.getService(Components.interfaces.nsIThreadManager).mainThread;
while (mainThread.hasPendingEvents()) // clear queue
mainThread.processNextEvent(true);
if (liberator.buffer.loaded == 1) if (liberator.buffer.loaded == 1)
return true; return true;
@@ -549,7 +546,7 @@ liberator.Events = function () //{{{
var then = new Date().getTime(); var then = new Date().getTime();
for (let now = then; now - then < ms; now = new Date().getTime()) for (let now = then; now - then < ms; now = new Date().getTime())
{ {
mainThread.processNextEvent(true); liberator.threadyield();
if ((now - then) % 1000 < 10) if ((now - then) % 1000 < 10)
liberator.dump("waited: " + (now - then) + " ms\n"); liberator.dump("waited: " + (now - then) + " ms\n");
@@ -1196,7 +1193,6 @@ liberator.Events = function () //{{{
if (liberator.modes.isReplaying) if (liberator.modes.isReplaying)
{ {
// XXX: Prevents using <C-c> in a macro.
if (key == "<C-c>" && !event.isMacro) if (key == "<C-c>" && !event.isMacro)
{ {
liberator.modes.isReplaying = false; liberator.modes.isReplaying = false;
@@ -1207,6 +1203,9 @@ liberator.Events = function () //{{{
} }
} }
if (key == "<C-c>")
liberator.interrupted = true;
var stop = true; // set to false if we should NOT consume this event but let Firefox handle it var stop = true; // set to false if we should NOT consume this event but let Firefox handle it
var win = document.commandDispatcher.focusedWindow; var win = document.commandDispatcher.focusedWindow;

View File

@@ -195,6 +195,8 @@ liberator.Search = function () //{{{
this.endPt.setStart(body, count); this.endPt.setStart(body, count);
this.endPt.setEnd(body, count); this.endPt.setEnd(body, count);
liberator.interrupted = false;
let n = 0;
for (let retRange in this.search(aWord, caseSensitive)) for (let retRange in this.search(aWord, caseSensitive))
{ {
// Highlight // Highlight
@@ -203,6 +205,10 @@ liberator.Search = function () //{{{
this.startPt = node.ownerDocument.createRange(); this.startPt = node.ownerDocument.createRange();
this.startPt.setStart(node, node.childNodes.length); this.startPt.setStart(node, node.childNodes.length);
this.startPt.setEnd(node, node.childNodes.length); this.startPt.setEnd(node, node.childNodes.length);
if (n++ % 20 == 0)
liberator.threadyield();
if (liberator.interrupted)
break;
} }
}, },

View File

@@ -647,10 +647,7 @@ liberator.Hints = function () //{{{
generate(win); generate(win);
// get all keys from the input queue // get all keys from the input queue
var mt = Components.classes["@mozilla.org/thread-manager;1"] liberator.threadyield(true);
.getService().mainThread;
while (mt.hasPendingEvents())
mt.processNextEvent(true);
canUpdate = true; canUpdate = true;
showHints(); showHints();

View File

@@ -1237,6 +1237,14 @@ const liberator = (function () //{{{
return true; return true;
}, },
threadyield: function (flush)
{
let mainThread = threadManager.mainThread;
do
mainThread.processNextEvent(true);
while (flush && mainThread.hasPendingEvents());
},
get windows() get windows()
{ {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]