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

Use completion.buffer for tabs.switchTo/:buffer!.

--HG--
extra : rebase_source : 91bb7fa4c4573048721f65c3aa871370300e7979
This commit is contained in:
Kris Maglione
2010-12-06 22:57:04 -05:00
parent 9c0cc5d19b
commit 175cd126b7
3 changed files with 22 additions and 42 deletions

View File

@@ -1177,7 +1177,7 @@ const Commands = Module("commands", {
return; return;
} }
[prefix] = args.commandString.match(/^(?:\w*[\s!])?\s*/); [, prefix] = args.commandString.match(/^[\s\d]*((?:\w*[\s!])?\s*)/);
let cmdContext = context.fork(command.name, prefix.length); let cmdContext = context.fork(command.name, prefix.length);
try { try {
if (!cmdContext.waitingForTab) { if (!cmdContext.waitingForTab) {

View File

@@ -411,9 +411,6 @@ const Tabs = Module("tabs", {
*/ */
// FIXME: help! // FIXME: help!
switchTo: function (buffer, allowNonUnique, count, reverse) { switchTo: function (buffer, allowNonUnique, count, reverse) {
if (buffer == "")
return;
if (buffer != null) { if (buffer != null) {
// store this command, so it can be repeated with "B" // store this command, so it can be repeated with "B"
this._lastBufferSwitchArgs = buffer; this._lastBufferSwitchArgs = buffer;
@@ -425,33 +422,21 @@ const Tabs = Module("tabs", {
allowNonUnique = this._lastBufferSwitchSpecial; allowNonUnique = this._lastBufferSwitchSpecial;
} }
if (buffer == "#") { if (buffer == "#")
tabs.selectAlternateTab(); return tabs.selectAlternateTab();
return;
}
count = Math.max(1, count || 1); count = Math.max(1, count || 1);
reverse = Boolean(reverse); reverse = Boolean(reverse);
let matches = buffer.match(/^(\d+):?/); let matches = buffer.match(/^(\d+):?/);
if (matches) { if (matches)
tabs.select(this.allTabs[parseInt(matches[1], 10) - 1], false); return tabs.select(this.allTabs[parseInt(matches[1], 10) - 1], false);
return;
}
matches = []; matches = array.first(tabs.allTabs, function (t) t.linkedBrowser.lastURI.spec === buffer);
let lowerBuffer = buffer.toLowerCase(); if (matches)
let first = tabs.index() + (reverse ? 0 : 1); return tabs.select(matches, false);
let allTabs = tabs.allTabs;
for (let [i, ] in Iterator(tabs.allTabs)) {
let tab = allTabs[(i + first) % allTabs.length];
let url = tab.linkedBrowser.contentDocument.location.href;
if (url == buffer)
return tabs.select(index, false);
if (url.indexOf(buffer) >= 0 || tab.label.toLowerCase().indexOf(lowerBuffer) >= 0) matches = completion.runCompleter("buffer", buffer);
matches.push(tab);
}
if (matches.length == 0) if (matches.length == 0)
dactyl.echoerr("E94: No matching buffer for " + buffer); dactyl.echoerr("E94: No matching buffer for " + buffer);
@@ -461,7 +446,7 @@ const Tabs = Module("tabs", {
let index = (count - 1) % matches.length; let index = (count - 1) % matches.length;
if (reverse) if (reverse)
index = matches.length - count; index = matches.length - count;
tabs.select(matches[index], false); tabs.select(matches[index].id, false);
} }
}, },
@@ -662,25 +647,9 @@ const Tabs = Module("tabs", {
{ argCount: "0" }); { argCount: "0" });
if (config.hasTabbrowser) { if (config.hasTabbrowser) {
// TODO: "Zero count" if 0 specified as arg, multiple args and count ranges?
commands.add(["b[uffer]"], commands.add(["b[uffer]"],
"Switch to a buffer", "Switch to a buffer",
function (args) { function (args) { tabs.switchTo(args[0], args.bang, args.count); }, {
let special = args.bang;
let count = args.count;
let arg = args[0];
// if a numeric arg is specified any count is ignored; if a
// count and non-numeric arg are both specified then E488
if (arg && count > 0) {
dactyl.assert(/^\d+$/.test(arg), "E488: Trailing characters");
tabs.switchTo(arg, special);
}
else if (count > 0)
tabs.switchTo(count.toString(), special);
else
tabs.switchTo(arg, special);
}, {
argCount: "?", argCount: "?",
bang: true, bang: true,
count: true, count: true,

View File

@@ -1071,6 +1071,17 @@ const array = Class("array", Array, {
equals: function (ary1, ary2) equals: function (ary1, ary2)
ary1.length === ary2.length && Array.every(ary1, function (e, i) e === ary2[i]), ary1.length === ary2.length && Array.every(ary1, function (e, i) e === ary2[i]),
/**
* Returns the first member of the given array that matches the
* given predicate.
*/
first: function first(ary, pred, self) {
for (let elem in values(ary))
if (pred.call(self, elem))
return elem;
return undefined;
},
/** /**
* Flattens an array, such that all elements of the array are * Flattens an array, such that all elements of the array are
* joined into a single array: * joined into a single array: