1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-11 22:25:47 +01:00

Fix some URL marks issues.

This commit is contained in:
Kris Maglione
2011-01-11 19:42:11 -05:00
parent 4b33fc5c9f
commit cff1888ea6

View File

@@ -97,48 +97,63 @@ var Marks = Module("marks", {
/** /**
* Jumps to the named mark. See {@link #add} * Jumps to the named mark. See {@link #add}
* *
* @param {string} mark The mark to jump to. * @param {string} char The mark to jump to.
*/ */
jumpTo: function (mark) { jumpTo: function (char) {
if (Marks.isURLMark(mark)) { if (Marks.isURLMark(char)) {
let slice = this._urlMarks.get(mark); let mark = this._urlMarks.get(char);
let tab = slice && slice.tab && slice.tab.get(); dactyl.assert(mark, "E20: Mark not set: " + char);
if (tab && tab.linkedBrowser) {
if (tab.parentNode != config.browser.tabContainer) { let tab = mark.tab && mark.tab.get();
this._pendingJumps.push(slice); if (!tab || !tab.linkedBrowser || tabs.allTabs.indexOf(tab) == -1)
// NOTE: this obviously won't work on generated pages using for ([, tab] in iter(tabs.visibleTabs, tabs.allTabs)) {
// non-unique URLs :( if (tab.linkedBrowser.contentDocument.documentURI === mark.location)
dactyl.open(slice.location, dactyl.NEW_TAB); break;
return; tab = null;
} }
let index = tabs.index(tab);
if (index != -1) { if (tab) {
tabs.select(index); tabs.select(tab);
let win = tab.linkedBrowser.contentWindow; let doc = tab.linkedBrowser.contentDocument;
if (win.location.href != slice.location) { if (doc.documentURI == mark.location) {
this._pendingJumps.push(slice); dactyl.log("Jumping to URL mark: " + Marks.markToString(char, mark), 5);
win.location.href = slice.location; buffer.scrollToPercent(mark.position.x * 100, mark.position.y * 100);
return; }
else {
this._pendingJumps.push(mark);
let sh = tab.linkedBrowser.sessionHistory;
let items = array(util.range(0, sh.count));
let a = items.slice(0, sh.index).reverse();
let b = items.slice(sh.index, sh.count);
a.length = b.length = Math.max(a.length, b.length);
items = array(a).zip(b).flatten().compact();
for (let i in items.iterValues()) {
let entry = sh.getEntryAtIndex(i, false);
util.dump(i, entry.URI.spec, entry.URI.spec.replace(/#.*/, "") == mark.location);
if (entry.URI.spec.replace(/#.*/, "") == mark.location)
return void tab.linkedBrowser.webNavigation.gotoIndex(i);
} }
dactyl.log("Jumping to URL mark: " + Marks.markToString(mark, slice), 5); dactyl.open(mark.location);
buffer.scrollToPercent(slice.position.x * 100, slice.position.y * 100);
return;
} }
} }
// FIXME This is stupid, but perhaps better than the current else {
// behaviour (persisting URL marks that will just signal an error). this._pendingJumps.push(mark);
else dactyl.open(mark.location, dactyl.NEW_TAB);
this._pendingJumps.push(slice); }
dactyl.open(slice.location, dactyl.NEW_TAB);
return;
} }
let mobj = Marks.isLocalMark(mark) && (this._localMarks.get(this.localURI) || {})[mark]; else if (Marks.isLocalMark(char)) {
if (mobj) { let mark = (this._localMarks.get(this.localURI) || {})[char];
dactyl.log("Jumping to local mark: " + Marks.markToString(mark, mobj), 5); dactyl.assert(mark, "E20: Mark not set: " + char);
buffer.scrollToPercent(mobj.position.x * 100, mobj.position.y * 100);
return; dactyl.log("Jumping to local mark: " + Marks.markToString(char, mark), 5);
buffer.scrollToPercent(mark.position.x * 100, mark.position.y * 100);
} }
dactyl.echoerr("E20: Mark not set"); else
dactyl.echoerr("E20: Invalid mark");
}, },
/** /**