1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 23:37:59 +01:00

Clear highlighting on page unload, etc.

This commit is contained in:
Kris Maglione
2009-11-13 19:17:34 -05:00
parent a9f8e825b9
commit 00697620ca
5 changed files with 80 additions and 13 deletions

View File

@@ -345,6 +345,18 @@ const Buffer = Module("buffer", {
window.content.document.pageIsFullyLoaded = value; window.content.document.pageIsFullyLoaded = value;
}, },
/**
* @property {Object} The local state store for the currently selected
* tab.
*/
get localStore() {
if (!content.liberatorStore)
content.liberatorStore = {};
return content.liberatorStore;
},
/** /**
* @property {Node} The last focused input field in the buffer. Used * @property {Node} The last focused input field in the buffer. Used
* by the "gi" key binding. * by the "gi" key binding.

View File

@@ -1115,25 +1115,46 @@ const Completion = Module("completion", {
context.filters.push(function (item) util.compareIgnoreCase(item.text.substr(0, this.filter.length), this.filter)); context.filters.push(function (item) util.compareIgnoreCase(item.text.substr(0, this.filter.length), this.filter));
if (obj == cache.evalContext) if (obj == cache.evalContext)
context.regenerate = true; context.regenerate = true;
context.generate = function () self.objectKeys(obj, !recurse); context.generate = function () {
try {
return self.objectKeys(obj, !recurse)
}
catch(e) {
liberator.reportError(e);
}
};
}; };
} }
// TODO: Make this a generic completion helper function. // TODO: Make this a generic completion helper function.
let filter = key + (string || ""); let filter = key + (string || "");
for (let [, obj] in Iterator(objects)) { for (let [, obj] in Iterator(objects)) {
this.context.fork(obj[1], top[OFFSET], this, fill, this.context.fork(obj[1], top[OFFSET], this, fill,
obj[0], obj[1], compl, compl != orig, filter, last, key.length); obj[0], obj[1], compl,
true, filter, last, key.length);
} }
if (orig) if (orig)
return; return;
for (let [, obj] in Iterator(objects)) { for (let [, obj] in Iterator(objects)) {
let name = obj[1] + " (prototypes)"; let name = obj[1] + " (prototypes)";
this.context.fork(name, top[OFFSET], this, fill, this.context.fork(name, top[OFFSET], this, fill,
obj[0], name, function (a, b) compl(a, b, true), compl != orig, obj[0], name, function (a, b) compl(a, b, true),
filter, last, key.length); true, filter, last, key.length);
obj[1] += " (substrings)"; }
for (let [, obj] in Iterator(objects)) {
let name = obj[1] + " (substrings)";
this.context.fork(obj[1], top[OFFSET], this, fill, this.context.fork(obj[1], top[OFFSET], this, fill,
obj[0], obj[1], compl, false, filter, last, key.length); obj[0], name, compl,
false, filter, last, key.length);
}
for (let [, obj] in Iterator(objects)) {
let name = obj[1] + " (prototype substrings)";
this.context.fork(obj[1], top[OFFSET], this, fill,
obj[0], name, function (a, b) compl(a, b, true),
false, filter, last, key.length);
} }
} }

View File

@@ -475,6 +475,9 @@ const RangeFinder = Module("rangefinder", {
}, },
bootstrap: function (str, backward) { bootstrap: function (str, backward) {
if (this.rangeFind && this.rangeFind.stale)
this.rangeFind = null;
let highlighted = this.rangeFind && this.rangeFind.highlighted; let highlighted = this.rangeFind && this.rangeFind.highlighted;
let matchCase = !(options["ignorecase"] || options["smartcase"] && !/[A-Z]/.test(str)); let matchCase = !(options["ignorecase"] || options["smartcase"] && !/[A-Z]/.test(str));
let linksOnly = options["linksearch"]; let linksOnly = options["linksearch"];
@@ -493,7 +496,11 @@ const RangeFinder = Module("rangefinder", {
return n1; return n1;
return ""; return "";
}); });
if (!this.rangeFind || linksOnly ^ !!this.rangeFind.elementPath ||
// It's possible, with :tabdetach, for the rangeFind to actually move
// from one window to another, which breaks things.
if (!this.rangeFind || this.rangeFind.window != window ||
linksOnly ^ !!this.rangeFind.elementPath ||
matchCase ^ this.rangeFind.matchCase || backward ^ this.rangeFind.reverse) { matchCase ^ this.rangeFind.matchCase || backward ^ this.rangeFind.reverse) {
if (this.rangeFind) if (this.rangeFind)
this.rangeFind.cancel(); this.rangeFind.cancel();
@@ -562,8 +569,8 @@ const RangeFinder = Module("rangefinder", {
this.rangeFind.cancel(); this.rangeFind.cancel();
}, },
get rangeFind() tabs.localStore.rangeFind, get rangeFind() buffer.localStore.rangeFind,
set rangeFind(val) tabs.localStore.rangeFind = val, set rangeFind(val) buffer.localStore.rangeFind = val,
/** /**
* Highlights all occurances of <b>str</b> in the buffer. * Highlights all occurances of <b>str</b> in the buffer.
@@ -640,6 +647,7 @@ const RangeFinder = Module("rangefinder", {
const RangeFind = Class("RangeFind", { const RangeFind = Class("RangeFind", {
init: function (matchCase, backward, elementPath) { init: function (matchCase, backward, elementPath) {
this.window = window;
this.elementPath = elementPath || null; this.elementPath = elementPath || null;
this.matchCase = Boolean(matchCase); this.matchCase = Boolean(matchCase);
this.reverse = Boolean(backward); this.reverse = Boolean(backward);
@@ -898,15 +906,35 @@ const RangeFind = Class("RangeFind", {
action(r); action(r);
this.lastRange = r; this.lastRange = r;
} }
if (clear) if (clear) {
this.highlighted = null; this.highlighted = null;
this.purgeListeners();
}
else { else {
this.highlighted = this.lastString; this.highlighted = this.lastString;
this.addListeners();
this.search(null, false); this.search(null, false);
} }
}, },
addListeners: function () {
for (let range in values(this.ranges))
range.window.addEventListener("unload", this.closure.onUnload, true);
},
purgeListeners: function () {
for (let range in values(this.ranges))
range.window.removeEventListener("unload", this.closure.onUnload, true);
},
onUnload: function (event) {
this.purgeListeners();
if (this.highlighted)
this.highlight(false);
this.stale = true;
},
cancel: function () { cancel: function () {
this.purgeListeners();
this.range.deselect(); this.range.deselect();
this.range.descroll() this.range.descroll()
} }
@@ -950,9 +978,11 @@ const RangeFind = Class("RangeFind", {
}, },
get docShell() { get docShell() {
if (this._docShell)
return this._docShell;
for (let shell in iter(getBrowser().docShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem.typeAll, Ci.nsIDocShell.ENUMERATE_FORWARDS))) for (let shell in iter(getBrowser().docShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem.typeAll, Ci.nsIDocShell.ENUMERATE_FORWARDS)))
if (shell.QueryInterface(nsIWebNavigation).document == this.document) if (shell.QueryInterface(nsIWebNavigation).document == this.document)
return shell; return this._docShell = shell;
}, },
get selectionController() this.docShell get selectionController() this.docShell
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor)

View File

@@ -979,7 +979,7 @@ const Hints = Module("hints", {
if (typeof a[2] == "string") if (typeof a[2] == "string")
a[3] = function (chr) String.fromCharCode(this[2].charCodeAt(0) + chr - this[0]) a[3] = function (chr) String.fromCharCode(this[2].charCodeAt(0) + chr - this[0])
else else
a[3] = function (chr) this[2][(chr - this[0]) % this[3].length]; a[3] = function (chr) this[2][(chr - this[0]) % this[2].length];
return a; return a;
}); });

View File

@@ -104,6 +104,10 @@ const Tabs = Module("tabs", {
* @returns {Object} * @returns {Object}
*/ */
// FIXME: why not a tab arg? Why this and the property? // FIXME: why not a tab arg? Why this and the property?
// : To the latter question, because this works for any tab, the
// property doesn't. And the property is so oft-used that it's
// convenient. To the former question, because I think this is mainly
// useful for autocommands, and they get index arguments. --Kris
getLocalStore: function (tabIndex) { getLocalStore: function (tabIndex) {
let tab = this.getTab(tabIndex); let tab = this.getTab(tabIndex);
if (!tab.liberatorStore) if (!tab.liberatorStore)