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

Fix local mapping bug. Change statusline API slightly.

This commit is contained in:
Kris Maglione
2011-02-28 19:44:46 -05:00
parent 74fbc5833f
commit ea6c7cc800
9 changed files with 89 additions and 82 deletions

View File

@@ -20,7 +20,7 @@ var Bookmarks = Module("bookmarks", {
valueOf: function () arg valueOf: function () arg
} }
}, arg)); }, arg));
statusline.updateUrl(); statusline.updateStatus();
}, window); }, window);
}, },

View File

@@ -76,7 +76,7 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
// hacky way to get rid of "Transferring data from ..." on sites with frames // hacky way to get rid of "Transferring data from ..." on sites with frames
// when you click on a link inside a frameset, because asyncUpdateUI // when you click on a link inside a frameset, because asyncUpdateUI
// is not triggered there (Gecko bug?) // is not triggered there (Gecko bug?)
this.timeout(function () { statusline.updateUrl(); }, 10); this.timeout(function () { statusline.updateStatus(); }, 10);
} }
else { else {
// code which should happen for all (also background) newly loaded tabs goes here: // code which should happen for all (also background) newly loaded tabs goes here:
@@ -160,7 +160,7 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
// called at the very end of a page load // called at the very end of a page load
asyncUpdateUI: util.wrapCallback(function asyncUpdateUI() { asyncUpdateUI: util.wrapCallback(function asyncUpdateUI() {
asyncUpdateUI.superapply(this, arguments); asyncUpdateUI.superapply(this, arguments);
util.timeout(function () { statusline.updateUrl(); }, 100); util.timeout(function () { statusline.updateStatus(); }, 100);
}), }),
setOverLink: util.wrapCallback(function setOverLink(link, b) { setOverLink: util.wrapCallback(function setOverLink(link, b) {
setOverLink.superapply(this, arguments); setOverLink.superapply(this, arguments);
@@ -189,7 +189,7 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
function () { function () {
window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils) window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils)
.redraw(); .redraw();
statusline.updateUrl(); statusline.updateStatus();
commandline.clear(); commandline.clear();
}, },
{ argCount: "0" }); { argCount: "0" });

View File

@@ -65,7 +65,7 @@ var ProcessorStack = Class("ProcessorStack", {
this.processors.length = 0; this.processors.length = 0;
if (this.ownsBuffer) if (this.ownsBuffer)
statusline.updateInputBuffer(this.processors.length ? this.buffer : ""); statusline.inputBuffer = this.processors.length ? this.buffer : "";
if (!this.processors.some(function (p) !p.extended) && this.actions.length) { if (!this.processors.some(function (p) !p.extended) && this.actions.length) {
if (this._actions.length == 0) { if (this._actions.length == 0) {

View File

@@ -668,8 +668,8 @@ var HintSession = Class("HintSession", CommandMode, {
* Display the current status to the user. * Display the current status to the user.
*/ */
updateStatusline: function _updateStatusline() { updateStatusline: function _updateStatusline() {
statusline.updateInputBuffer((this.escapeNumbers ? options["mapleader"] : "") + statusline.inputBuffer = (this.escapeNumbers ? options["mapleader"] : "") +
(this.hintNumber ? this.getHintString(this.hintNumber) : "")); (this.hintNumber ? this.getHintString(this.hintNumber) : "");
}, },
}); });

View File

@@ -184,7 +184,7 @@ var Modes = Module("modes", {
if (prefs.get("accessibility.browsewithcaret")) if (prefs.get("accessibility.browsewithcaret"))
prefs.set("accessibility.browsewithcaret", false); prefs.set("accessibility.browsewithcaret", false);
statusline.updateUrl(); statusline.updateStatus();
if (!stack.fromFocus && prev.main.ownsFocus) if (!stack.fromFocus && prev.main.ownsFocus)
dactyl.focusContent(true); dactyl.focusContent(true);
if (prev.main == modes.NORMAL) { if (prev.main == modes.NORMAL) {

View File

@@ -15,7 +15,7 @@ var QuickMarks = Module("quickmarks", {
init: function () { init: function () {
this._qmarks = storage.newMap("quickmarks", { store: true }); this._qmarks = storage.newMap("quickmarks", { store: true });
storage.addObserver("quickmarks", function () { storage.addObserver("quickmarks", function () {
statusline.updateUrl(); statusline.updateStatus();
}, window); }, window);
}, },

View File

@@ -95,7 +95,7 @@ var StatusLine = Module("statusline", {
signals: { signals: {
"browser.locationChange": function (webProgress, request, uri) { "browser.locationChange": function (webProgress, request, uri) {
let win = webProgress.DOMWindow; let win = webProgress.DOMWindow;
this.updateUrl(); this.status = buffer.uri;
this.progress = uri && win && win.dactylProgress || ""; this.progress = uri && win && win.dactylProgress || "";
// if this is not delayed we get the position of the old buffer // if this is not delayed we get the position of the old buffer
@@ -107,7 +107,7 @@ var StatusLine = Module("statusline", {
"browser.overLink": function (link) { "browser.overLink": function (link) {
switch (options["showstatuslinks"]) { switch (options["showstatuslinks"]) {
case "status": case "status":
this.updateUrl(link ? _("status.link", link) : null); this.status = link ? _("status.link", link) : buffer.uri;
break; break;
case "command": case "command":
if (link) if (link)
@@ -141,11 +141,11 @@ var StatusLine = Module("statusline", {
this.progress = 0; this.progress = 0;
if (flags & Ci.nsIWebProgressListener.STATE_STOP) { if (flags & Ci.nsIWebProgressListener.STATE_STOP) {
this.progress = ""; this.progress = "";
this.updateUrl(); this.status = buffer.uri;
} }
}, },
"browser.statusChange": function onStatusChange(webProgress, request, status, message) { "browser.statusChange": function onStatusChange(webProgress, request, status, message) {
this.updateUrl(message); this.status = message || buffer.uri;
}, },
}, },
@@ -174,14 +174,43 @@ var StatusLine = Module("statusline", {
// update all fields of the statusline // update all fields of the statusline
update: function update() { update: function update() {
this.updateUrl(); this.status = buffer.uri;
this.updateInputBuffer(); this.inputBuffer = "";
this.updateProgress(); this.progress = "";
this.updateTabCount(); this.updateTabCount();
this.updateBufferPosition(); this.updateBufferPosition();
this.updateZoomLevel(); this.updateZoomLevel();
}, },
// ripped from Firefox; modified
unsafeURI: util.regexp(String.replace(<![CDATA[
[
\s
// Invisible characters (bug 452979)
U001C U001D U001E U001F // file/group/record/unit separator
U00AD // Soft hyphen
UFEFF // BOM
U2060 // Word joiner
U2062 U2063 // Invisible times/separator
U200B UFFFC // Zero-width space/no-break space
// Bidi formatting characters. (RFC 3987 sections 3.2 and 4.1 paragraph 6)
U200E U200F U202A U202B U202C U202D U202E
]
]]>, /U/g, "\\u"),
"gx"),
losslessDecodeURI: function losslessDecodeURI(url) {
return url.split("%25").map(function (url) {
// Non-UTF-8 compliant URLs cause "malformed URI sequence" errors.
try {
return decodeURI(url).replace(this.unsafeURI, encodeURIComponent);
}
catch (e) {
return url;
}
}, this).join("%25");
},
/** /**
* Update the URL displayed in the status line. Also displays status * Update the URL displayed in the status line. Also displays status
* icons, [+-♥], when there are next and previous pages in the * icons, [+-♥], when there are next and previous pages in the
@@ -189,64 +218,32 @@ var StatusLine = Module("statusline", {
* respectively. * respectively.
* *
* @param {string} url The URL to display. * @param {string} url The URL to display.
* @default buffer.uri
*/ */
updateUrl: function updateUrl(url) { get status() this._uri,
// ripped from Firefox; modified set status(uri) {
function losslessDecodeURI(url) {
// 1. decodeURI decodes %25 to %, which creates unintended
// encoding sequences.
url = url.split("%25").map(function (url) {
// Non-UTF-8 compliant URLs cause "malformed URI sequence" errors.
try {
return decodeURI(url);
}
catch (e) {
return url;
}
}).join("%25");
// 2. Re-encode whitespace so that it doesn't get eaten away
// by the location bar (bug 410726).
url = url.replace(/[\r\n\t]/g, encodeURIComponent);
// Encode invisible characters (soft hyphen, zero-width space, BOM,
// line and paragraph separator, word joiner, invisible times,
// invisible separator, object replacement character) (bug 452979)
url = url.replace(/[\v\x0c\x1c\x1d\x1e\x1f\u00ad\u200b\ufeff\u2028\u2029\u2060\u2062\u2063\ufffc]/g,
encodeURIComponent);
// Encode bidirectional formatting characters.
// (RFC 3987 sections 3.2 and 4.1 paragraph 6)
url = url.replace(/[\u200e\u200f\u202a\u202b\u202c\u202d\u202e]/g,
encodeURIComponent);
return url;
};
// TODO: this probably needs a more general solution.
if (url == null)
url = buffer.uri.spec;
// when session information is available, add [+] when we can go
// backwards, [-] when we can go forwards
let modified = ""; let modified = "";
if (url === buffer.uri.spec) { let url = uri;
if (window.getWebNavigation) { if (isinstance(uri, Ci.nsIURI)) {
// when session information is available, add [+] when we can go
// backwards, [-] when we can go forwards
if (uri.equals(buffer.uri) && window.getWebNavigation) {
let sh = window.getWebNavigation().sessionHistory; let sh = window.getWebNavigation().sessionHistory;
if (sh && sh.index > 0) if (sh && sh.index > 0)
modified += "+"; modified += "+";
if (sh && sh.index < sh.count - 1) if (sh && sh.index < sh.count - 1)
modified += "-"; modified += "-";
} }
if (modules.bookmarkcache) {
if (bookmarkcache.isBookmarked(url))
modified += UTF8("❤");
//modified += UTF8("♥");
}
if (modules.quickmarks)
modified += quickmarks.find(url.replace(/#.*/, "")).join("");
}
url = losslessDecodeURI(url); if (modules.bookmarkcache) {
if (bookmarkcache.isBookmarked(uri))
modified += UTF8("❤");
}
if (modules.quickmarks)
modified += quickmarks.find(uri.spec.replace(/#.*/, "")).join("");
url = this.losslessDecodeURI(uri.spec);
}
if (url == "about:blank") { if (url == "about:blank") {
if (!buffer.title) if (!buffer.title)
@@ -261,8 +258,14 @@ var StatusLine = Module("statusline", {
url += " [" + modified + "]"; url += " [" + modified + "]";
this.widgets.url.value = url; this.widgets.url.value = url;
this._status = uri;
}, },
updateStatus: function updateStatus() { this.status = buffer.uri; },
updateUrl: deprecated("statusline.status", function updateUrl(url) { this.status = url || buffer.uri }),
/** /**
* Set the contents of the status line's input buffer to the given * Set the contents of the status line's input buffer to the given
* string. Used primarily when a key press requires further input * string. Used primarily when a key press requires further input
@@ -272,12 +275,9 @@ var StatusLine = Module("statusline", {
* @param {string} buffer * @param {string} buffer
* @optional * @optional
*/ */
updateInputBuffer: function updateInputBuffer(buffer) { get inputBuffer() this.widgets.inputbuffer.value,
if (buffer == null) set inputBuffer(val) this.widgets.inputbuffer.value = val == null ? "" : val,
buffer = ""; updateInputBuffer: deprecated("statusline.inputBuffer", function updateInputBuffer(val) { this.inputBuffer = val; }),
this.widgets.inputbuffer.value = buffer;
},
/** /**
* Update the page load progress bar. * Update the page load progress bar.
@@ -310,9 +310,9 @@ var StatusLine = Module("statusline", {
} }
} }
}), }),
updateProgress: function updateProgress(progress) { updateProgress: deprecated("statusline.progress", function updateProgress(progress) {
this.progress = progress; this.progress = progress;
}, }),
/** /**
* Display the correct tabcount (e.g., [1/5]) on the status bar. * Display the correct tabcount (e.g., [1/5]) on the status bar.

View File

@@ -875,15 +875,20 @@ Class.prototype = {
}; };
Class.makeClosure = function makeClosure() { Class.makeClosure = function makeClosure() {
const self = this; const self = this;
function closure(fn) function _closure() { function closure(fn) {
try { function _closure() {
return fn.apply(self, arguments); try {
} return fn.apply(self, arguments);
catch (e if !(e instanceof FailedAssertion)) { }
util.reportError(e); catch (e if !(e instanceof FailedAssertion)) {
throw e.stack ? e : Error(e); util.reportError(e);
throw e.stack ? e : Error(e);
}
} }
_closure.wrapped = fn;
return _closure;
} }
iter(properties(this), properties(this, true)).forEach(function (k) { iter(properties(this), properties(this, true)).forEach(function (k) {
if (!__lookupGetter__.call(this, k) && callable(this[k])) if (!__lookupGetter__.call(this, k) && callable(this[k]))
closure[k] = closure(this[k]); closure[k] = closure(this[k]);
@@ -895,6 +900,7 @@ Class.makeClosure = function makeClosure() {
set: function set_proxy(val) self[k] = val, set: function set_proxy(val) self[k] = val,
}); });
}, this); }, this);
return closure; return closure;
}; };
memoize(Class.prototype, "closure", Class.makeClosure); memoize(Class.prototype, "closure", Class.makeClosure);
@@ -981,11 +987,13 @@ Module.INIT = {
modules.jsmodules[this.constructor.className] = module; modules.jsmodules[this.constructor.className] = module;
locals.reverse().forEach(function (fn, i) update(objs[i], fn.apply(module, args))) locals.reverse().forEach(function (fn, i) update(objs[i], fn.apply(module, args)))
memoize(module, "closure", Class.makeClosure);
module.instance = module; module.instance = module;
module.init(); module.init();
if (module.signals) if (module.signals)
modules.dactyl.registerObservers modules.dactyl.registerObservers(module);
} }
} }
} }

View File

@@ -311,7 +311,6 @@ var Overlay = Module("Overlay", {
modules.events.listen(window, "unload", function onUnload() { modules.events.listen(window, "unload", function onUnload() {
window.removeEventListener("unload", onUnload.wrapped, false); window.removeEventListener("unload", onUnload.wrapped, false);
util.dump("unload", modules.moduleList);
for each (let mod in modules.moduleList.reverse()) { for each (let mod in modules.moduleList.reverse()) {
mod.stale = true; mod.stale = true;