// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
this.tabBinding = styles.system.add("tab-binding", "chrome://browser/content/browser.xul", literal(/*
xul|tab { -moz-binding: url(chrome://dactyl/content/bindings.xml#tab) !important; }
- */).replace(/tab-./g, function (m) config.OS.isMacOSX ? "tab-mac" : m),
+ */).replace(/tab-./g, m => config.OS.isMacOSX ? "tab-mac" : m),
false, true);
this.timeout(function () {
}
},
- _alternates: Class.Memoize(function () [config.tabbrowser.mCurrentTab, null]),
+ _alternates: Class.Memoize(() => [config.tabbrowser.mCurrentTab, null]),
cleanup: function cleanup() {
for (let [i, tab] in Iterator(this.allTabs)) {
*/
get options() this.localStore.options,
- get visibleTabs() config.tabbrowser.visibleTabs || this.allTabs.filter(function (tab) !tab.hidden),
+ get visibleTabs() config.tabbrowser.visibleTabs || this.allTabs.filter(tab => !tab.hidden),
/**
* Returns the local state store for the tab at the specified *tabIndex*.
this._groups = iframe ? iframe.contentWindow : null;
if (this._groups && !func)
- util.waitFor(function () this._groups.TabItems, this);
+ util.waitFor(() => this._groups.TabItems);
return this._groups;
},
* @param {number} count How many tabs to remove.
* @param {boolean} focusLeftTab Focus the tab to the left of the removed tab.
*/
- remove: function remove(tab, count, focusLeftTab) {
- count = count || 1;
+ remove: function remove(tab, count = 1, focusLeftTab = false) {
let res = this.count > count;
let tabs = this.visibleTabs;
}
if (focusLeftTab)
- tabs.slice(Math.max(0, index + 1 - count), index + 1).forEach(config.closure.removeTab);
+ tabs.slice(Math.max(0, index + 1 - count),
+ index + 1)
+ .forEach(config.closure.removeTab);
else
- tabs.slice(index, index + count).forEach(config.closure.removeTab);
+ tabs.slice(index,
+ index + count)
+ .forEach(config.closure.removeTab);
return res;
},
if (matches)
return tabs.select(this.allTabs[parseInt(matches[1], 10) - 1], false);
- matches = array.nth(tabs.allTabs, function (t) (t.linkedBrowser.lastURI || {}).spec === buffer, 0);
+ matches = array.nth(tabs.allTabs, t => (t.linkedBrowser.lastURI || {}).spec === buffer, 0);
if (matches)
return tabs.select(matches, false);
- matches = completion.runCompleter("buffer", buffer).map(function (obj) obj.tab);
+ matches = completion.runCompleter("buffer", buffer).map(obj => obj.tab);
if (matches.length == 0)
dactyl.echoerr(_("buffer.noMatching", buffer));
count: true,
completer: function (context, args) {
if (!args.bang)
- context.filters.push(function ({ item }) !item.tab.pinned);
+ context.filters.push(({ item }) => !item.tab.pinned);
completion.buffer(context);
}
});
argCount: "?",
count: true,
completer: function (context, args) {
- context.filters.push(function ({ item }) item.tab.pinned);
+ context.filters.push(({ item }) => item.tab.pinned);
completion.buffer(context);
}
});
commands.add(["tabl[ast]", "bl[ast]"],
"Switch to the last tab",
- function () tabs.select("$", false),
+ function () { tabs.select("$", false); },
{ argCount: "0" });
// TODO: "Zero count" if 0 specified as arg
if (config.has("tabbrowser")) {
commands.add(["b[uffer]"],
"Switch to a buffer",
- function (args) { tabs.switchTo(args[0], args.bang, args.count); }, {
+ function (args) {
+ if (args.length)
+ tabs.switchTo(args[0], args.bang, args.count);
+ else if (args.count)
+ tabs.switchTo(String(args.count));
+ }, {
argCount: "?",
bang: true,
count: true,
commands.add(["taba[ttach]"],
"Attach the current tab to another window",
function (args) {
- dactyl.assert(args.length <= 2 && !args.some(function (i) !/^\d+(?:$|:)/.test(i)),
+ dactyl.assert(args.length <= 2 && !args.some(i => !/^\d+(?:$|:)/.test(i)),
_("error.trailingCharacters"));
- let [winIndex, tabIndex] = args.map(function (arg) parseInt(arg));
+ let [winIndex, tabIndex] = args.map(arg => parseInt(arg));
if (args["-group"]) {
util.assert(args.length == 1);
window.TabView.moveTabTo(tabs.getTab(), winIndex);
let modules = win.dactyl.modules;
let { browser } = modules.config;
- if (args[1]) {
- let tabList = modules.tabs.visibleTabs;
- let target = dactyl.assert(tabList[tabIndex]);
- tabIndex = Array.indexOf(tabs.allTabs, target) - 1;
- }
-
let newTab = browser.addTab("about:blank");
browser.stop();
// XXX: the implementation of DnD in tabbrowser.xml suggests
// without this reference?
browser.docShell;
- let last = modules.tabs.allTabs.length - 1;
+ if (args[1]) {
+ let { visibleTabs, allTabs } = modules.tabs;
+ tabIndex = Math.constrain(tabIndex, 1, visibleTabs.length);
+ let target = visibleTabs[tabIndex - 1];
+ browser.moveTabTo(newTab, Array.indexOf(allTabs, target));
+ }
- if (args[1])
- browser.moveTabTo(newTab, tabIndex);
browser.selectedTab = newTab; // required
browser.swapBrowsersAndCloseOther(newTab, sourceTab);
}, {
if (args["-group"])
completion.tabGroup(context);
else {
- context.filters.push(function ({ item }) item != window);
+ context.filters.push(({ item }) => item != window);
completion.window(context);
}
break;
context.anchored = false;
context.compare = CompletionContext.Sort.unsorted;
context.filters = [CompletionContext.Filter.textDescription];
- context.keys = { text: function ([i, { state: s }]) (i + 1) + ": " + s.entries[s.index - 1].url, description: "[1].title", icon: "[1].image" };
+ context.keys = { text: function ([i, { state: s }]) (i + 1) + ": " + s.entries[s.index - 1].url,
+ description: "[1].title",
+ icon: "[1].image" };
context.completions = Iterator(tabs.closedTabs);
},
count: true,
for (let [id, vals] in Iterator(tabGroups))
context.fork(id, 0, this, function (context, [name, browsers]) {
context.title = [name || "Buffers"];
- context.generate = function ()
+ context.generate = () =>
Array.map(browsers, function ([i, browser]) {
let indicator = " ";
if (i == tabs.index())
context.keys = {
text: "id",
description: function (group) group.getTitle() ||
- group.getChildren().map(function (t) t.tab.label).join(", ")
+ group.getChildren().map(t => t.tab.label).join(", ")
};
context.generate = function () {
context.incomplete = true;
mappings.add([modes.NORMAL], ["d"],
"Delete current buffer",
- function ({ count }) { tabs.remove(tabs.getTab(), count, false); },
+ function ({ count }) { tabs.remove(tabs.getTab(), count || 1, false); },
{ count: true });
mappings.add([modes.NORMAL], ["D"],
"Delete current buffer, focus tab to the left",
- function ({ count }) { tabs.remove(tabs.getTab(), count, true); },
+ function ({ count }) { tabs.remove(tabs.getTab(), count || 1, true); },
{ count: true });
mappings.add([modes.NORMAL], ["gb"],