// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
/** @scope modules */
init: function init() {
let s = "dactyl-statusline-field-";
- XML.ignoreWhitespace = true;
overlay.overlayWindow(window, {
objects: {
eventTarget: commandline
},
- append: <e4x xmlns={XUL} xmlns:dactyl={NS}>
- <vbox id={config.ids.commandContainer}>
- <vbox class="dactyl-container" hidden="false" collapsed="true">
- <iframe class="dactyl-completions" id="dactyl-completions-dactyl-commandline" src="dactyl://content/buffer.xhtml"
- contextmenu="dactyl-contextmenu"
- flex="1" hidden="false" collapsed="false"
- highlight="Events" events="mowEvents" />
- </vbox>
-
- <stack orient="horizontal" align="stretch" class="dactyl-container" id="dactyl-container" highlight="CmdLine CmdCmdLine">
- <textbox class="plain" id="dactyl-strut" flex="1" crop="end" collapsed="true"/>
- <textbox class="plain" id="dactyl-mode" flex="1" crop="end"/>
- <textbox class="plain" id="dactyl-message" flex="1" readonly="true"/>
-
- <hbox id="dactyl-commandline" hidden="false" class="dactyl-container" highlight="Normal CmdNormal" collapsed="true">
- <label id="dactyl-commandline-prompt" class="dactyl-commandline-prompt plain" flex="0" crop="end" value="" collapsed="true"/>
- <textbox id="dactyl-commandline-command" class="dactyl-commandline-command plain" flex="1" type="input" timeout="100"
- highlight="Events" />
- </hbox>
- </stack>
-
- <vbox class="dactyl-container" hidden="false" collapsed="false" highlight="CmdLine">
- <textbox id="dactyl-multiline-input" class="plain" flex="1" rows="1" hidden="false" collapsed="true" multiline="true"
- highlight="Normal Events" events="multilineInputEvents" />
- </vbox>
- </vbox>
-
- <stack id="dactyl-statusline-stack">
- <hbox id={s + "commandline"} hidden="false" class="dactyl-container" highlight="Normal StatusNormal" collapsed="true">
- <label id={s + "commandline-prompt"} class="dactyl-commandline-prompt plain" flex="0" crop="end" value="" collapsed="true"/>
- <textbox id={s + "commandline-command"} class="dactyl-commandline-command plain" flex="1" type="text" timeout="100"
- highlight="Events" />
- </hbox>
- </stack>
- </e4x>.elements(),
-
- before: <e4x xmlns={XUL} xmlns:dactyl={NS}>
- <toolbar id={statusline.statusBar.id}>
- <vbox id={"dactyl-completions-" + s + "commandline-container"} class="dactyl-container" hidden="false" collapsed="true">
- <iframe class="dactyl-completions" id={"dactyl-completions-" + s + "commandline"} src="dactyl://content/buffer.xhtml"
- contextmenu="dactyl-contextmenu" flex="1" hidden="false" collapsed="false"
- highlight="Events" events="mowEvents" />
- </vbox>
- </toolbar>
- </e4x>.elements()
+ append: [
+ ["vbox", { id: config.ids.commandContainer, xmlns: "xul" },
+ ["vbox", { class: "dactyl-container", hidden: "false", collapsed: "true" },
+ ["iframe", { class: "dactyl-completions", id: "dactyl-completions-dactyl-commandline",
+ src: "dactyl://content/buffer.xhtml", contextmenu: "dactyl-contextmenu",
+ flex: "1", hidden: "false", collapsed: "false",
+ highlight: "Events", events: "mowEvents" }]],
+
+ ["stack", { orient: "horizontal", align: "stretch", class: "dactyl-container",
+ id: "dactyl-container", highlight: "CmdLine CmdCmdLine" },
+ ["textbox", { class: "plain", id: "dactyl-strut", flex: "1", crop: "end", collapsed: "true" }],
+ ["textbox", { class: "plain", id: "dactyl-mode", flex: "1", crop: "end" }],
+ ["hbox", { id: "dactyl-message-box" },
+ ["label", { class: "plain", id: "dactyl-message-pre", flex: "0", readonly: "true", highlight: "WarningMsg" }],
+ ["textbox", { class: "plain", id: "dactyl-message", flex: "1", readonly: "true" }]],
+
+ ["hbox", { id: "dactyl-commandline", hidden: "false", class: "dactyl-container", highlight: "Normal CmdNormal", collapsed: "true" },
+ ["label", { id: "dactyl-commandline-prompt", class: "dactyl-commandline-prompt plain", flex: "0", crop: "end", value: "", collapsed: "true" }],
+ ["textbox", { id: "dactyl-commandline-command", class: "dactyl-commandline-command plain", flex: "1", type: "input", timeout: "100",
+ highlight: "Events" }]]],
+
+ ["vbox", { class: "dactyl-container", hidden: "false", collapsed: "false", highlight: "CmdLine" },
+ ["textbox", { id: "dactyl-multiline-input", class: "plain", flex: "1", rows: "1", hidden: "false", collapsed: "true",
+ multiline: "true", highlight: "Normal Events", events: "multilineInputEvents" }]]],
+
+ ["stack", { id: "dactyl-statusline-stack", xmlns: "xul" },
+ ["hbox", { id: s + "commandline", hidden: "false", class: "dactyl-container", highlight: "Normal StatusNormal", collapsed: "true" },
+ ["label", { id: s + "commandline-prompt", class: "dactyl-commandline-prompt plain", flex: "0", crop: "end", value: "", collapsed: "true" }],
+ ["textbox", { id: s + "commandline-command", class: "dactyl-commandline-command plain", flex: "1", type: "text", timeout: "100",
+ highlight: "Events", }]]]],
+
+ before: [
+ ["toolbar", { id: statusline.statusBar.id, xmlns: "xul" },
+ ["vbox", { id: "dactyl-completions-" + s + "commandline-container", class: "dactyl-container", hidden: "false", collapsed: "true" },
+ ["iframe", { class: "dactyl-completions", id: "dactyl-completions-" + s + "commandline", src: "dactyl://content/buffer.xhtml",
+ contextmenu: "dactyl-contextmenu", flex: "1", hidden: "false", collapsed: "false", highlight: "Events",
+ events: "mowEvents" }]]]]
});
this.elements = {};
return this.statusbar;
let statusElem = this.statusbar.message;
- if (value && !value[2] && statusElem.editor && statusElem.editor.rootElement.scrollWidth > statusElem.scrollWidth)
+ // Currently doesn't work as expected with <hbox> parent.
+ if (false && value && !value[2] && statusElem.editor && statusElem.editor.rootElement.scrollWidth > statusElem.scrollWidth)
return this.commandbar;
return this.activeGroup.mode;
}
});
+ this.addElement({
+ name: "message-pre",
+ defaultGroup: "WarningMsg",
+ getGroup: function () this.activeGroup.message
+ });
+
+ this.addElement({
+ name: "message-box",
+ defaultGroup: "Normal",
+ getGroup: function () this.activeGroup.message,
+ getValue: function () this.message
+ });
+
this.addElement({
name: "mode",
defaultGroup: "ModeMsg",
function get(prefix, map, id) (obj.getElement || util.identity)(map[id] || document.getElementById(prefix + id));
- this.active.__defineGetter__(obj.name, function () self.activeGroup[obj.name][obj.name]);
- this.activeGroup.__defineGetter__(obj.name, function () self.getGroup(obj.name));
+ this.active.__defineGetter__(obj.name, () => this.activeGroup[obj.name][obj.name]);
+ this.activeGroup.__defineGetter__(obj.name, () => this.getGroup(obj.name));
- memoize(this.statusbar, obj.name, function () get("dactyl-statusline-field-", statusline.widgets, (obj.id || obj.name)));
- memoize(this.commandbar, obj.name, function () get("dactyl-", {}, (obj.id || obj.name)));
+ memoize(this.statusbar, obj.name, () => get("dactyl-statusline-field-", statusline.widgets, (obj.id || obj.name)));
+ memoize(this.commandbar, obj.name, () => get("dactyl-", {}, (obj.id || obj.name)));
if (!(obj.noValue || obj.getValue)) {
Object.defineProperty(this, obj.name, Modes.boundProperty({
highlight.highlightNode(elem,
(val[0] != null ? val[0] : obj.defaultGroup)
.split(/\s/).filter(util.identity)
- .map(function (g) g + " " + nodeSet.group + g)
+ .map(g => g + " " + nodeSet.group + g)
.join(" "));
elem.value = val[1];
if (obj.onChange)
let elem = nodeSet[obj.name];
if (elem)
highlight.highlightNode(elem, obj.defaultGroup.split(/\s/)
- .map(function (g) g + " " + nodeSet.group + g).join(" "));
+ .map(g => g + " " + nodeSet.group + g)
+ .join(" "));
});
}
},
},
updateVisibility: function updateVisibility() {
+ let changed = 0;
for (let elem in values(this.elements))
if (elem.getGroup) {
let value = elem.getValue ? elem.getValue.call(this)
let meth, node = group[elem.name];
let visible = (value && group === activeGroup);
if (node && !node.collapsed == !visible) {
+ changed++;
node.collapsed = !visible;
if (elem.onVisibility)
elem.onVisibility.call(this, node, visible);
// choose which element to select.
function check(node) {
if (DOM(node).style.display === "-moz-stack") {
- let nodes = Array.filter(node.children, function (n) !n.collapsed && n.boxObject.height);
- nodes.forEach(function (node, i) node.style.opacity = (i == nodes.length - 1) ? "" : "0");
+ let nodes = Array.filter(node.children, n => !n.collapsed && n.boxObject.height);
+ nodes.forEach((node, i) => {
+ node.style.opacity = (i == nodes.length - 1) ? "" : "0";
+ });
}
Array.forEach(node.children, check);
}
[this.commandbar.container, this.statusbar.container].forEach(check);
- if (this.initialized && loaded.mow && mow.visible)
+ if (this.initialized && loaded.has("mow") && mow.visible)
mow.resize(false);
},
return document.getElementById("dactyl-contextmenu");
}),
- multilineOutput: Class.Memoize(function () this._whenReady("dactyl-multiline-output", function (elem) {
+ multilineOutput: Class.Memoize(function () this._whenReady("dactyl-multiline-output",
+ elem => {
highlight.highlightNode(elem.contentDocument.body, "MOW");
}), true),
- multilineInput: Class.Memoize(function () document.getElementById("dactyl-multiline-input")),
+ multilineInput: Class.Memoize(() => document.getElementById("dactyl-multiline-input")),
- mowContainer: Class.Memoize(function () document.getElementById("dactyl-multiline-output-container"))
+ mowContainer: Class.Memoize(() => document.getElementById("dactyl-multiline-output-container"))
}, {
getEditor: function getEditor(elem) {
elem.inputField.QueryInterface(Ci.nsIDOMNSEditableElement);
false);
this.messageCount = commandline.messageCount;
- modes.push(this.mode, this.extendedMode, this.closure);
+ modes.push(this.mode, this.extendedMode, this.bound);
this.widgets.active.commandline.collapsed = false;
this.widgets.prompt = this.prompt;
init.supercall(this);
},
- complete: function CPM_complete(context) {
+ complete: function CPM_complete(context, ...args) {
if (this.completer)
- context.forkapply("prompt", 0, this, "completer", Array.slice(arguments, 1));
+ context.forkapply("prompt", 0, this, "completer", args);
},
get mode() modes.PROMPT
*/
var CommandLine = Module("commandline", {
init: function init() {
- const self = this;
-
this._callbacks = {};
memoize(this, "_store", function () storage.newMap("command-history", { store: true, privateData: true }));
}, this);
},
- widgets: Class.Memoize(function () CommandWidgets()),
+ widgets: Class.Memoize(() => CommandWidgets()),
runSilently: function runSilently(func, self) {
this.withSavedValues(["silent"], function () {
node.completionList = ItemList(elem);
node.completionList.isAboveMow = node.id ==
- this.widgets.statusbar.commandline.id
+ this.widgets.statusbar.commandline.id;
}
return node.completionList;
},
if (!scroll || Date.now() - this._lastEchoTime > 5000)
this.clearMessage();
this._lastEchoTime = 0;
+ this.hiddenMessages = 0;
if (!this.commandSession) {
this.widgets.command = null;
},
clearMessage: function clearMessage() {
- if (this.widgets.message && this.widgets.message[1] === this._lastClearable)
+ if (this.widgets.message && this.widgets.message[1] === this._lastClearable) {
this.widgets.message = null;
+ this.hiddenMessages = 0;
+ }
},
/**
* Displays the multi-line output of a command, preceded by the last
* executed ex command string.
*
- * @param {XML} xml The output as an E4X XML object.
+ * @param {object} xml The output as a JSON XML object.
*/
commandOutput: function commandOutput(xml) {
- XML.ignoreWhitespace = XML.prettyPrinting = false;
- if (this.command)
- this.echo(<><div xmlns={XHTML}>:{this.command}</div>
{xml}</>, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
- else
+ if (!this.command)
this.echo(xml, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
+ else
+ this.echo([["div", { xmlns: "html" }, ":" + this.command], "\n", xml],
+ this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
this.command = null;
},
let field = this.widgets.active.message.inputField;
if (field.value && !forceSingle && field.editor.rootElement.scrollWidth > field.scrollWidth) {
this.widgets.message = null;
- mow.echo(<span highlight="Message">{str}</span>, highlightGroup, true);
+ mow.echo(["span", { highlight: "Message" }, str], highlightGroup, true);
}
},
+ _hiddenMessages: 0,
+ get hiddenMessages() this._hiddenMessages,
+ set hiddenMessages(val) {
+ this._hiddenMessages = val;
+ if (val)
+ this.widgets["message-pre"] = _("commandline.moreMessages", val) + " ";
+ else
+ this.widgets["message-pre"] = null;
+ },
+
_lastEcho: null,
/**
highlightGroup = highlightGroup || this.HL_NORMAL;
- if (flags & this.APPEND_TO_MESSAGES) {
- let message = isObject(data) ? data : { message: data };
+ let appendToMessages = (data) => {
+ let message = isObject(data) && !DOM.isJSONXML(data) ? data : { message: data };
// Make sure the memoized message property is an instance property.
message.message;
this._messageHistory.add(update({ highlight: highlightGroup }, message));
- data = message.message;
+ return message.message;
}
+ if (flags & this.APPEND_TO_MESSAGES)
+ data = appendToMessages(data);
+
if ((flags & this.ACTIVE_WINDOW) && window != overlay.activeWindow)
return;
if ((flags & this.DISALLOW_MULTILINE) && !this.widgets.mowContainer.collapsed)
return;
- let single = flags & (this.FORCE_SINGLELINE | this.DISALLOW_MULTILINE);
+ let forceSingle = flags & (this.FORCE_SINGLELINE | this.DISALLOW_MULTILINE);
let action = this._echoLine;
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(data) || !isinstance(data, [_, "String"])) && !(flags & this.FORCE_SINGLELINE))
- action = mow.closure.echo;
+ action = mow.bound.echo;
+
+ let checkSingleLine = () => action == this._echoLine;
- if (single)
+ if (forceSingle) {
this._lastEcho = null;
+ this.hiddenMessages = 0;
+ }
else {
- if (this.widgets.message && this.widgets.message[1] == this._lastEcho)
- mow.echo(<span highlight="Message">{this._lastEcho}</span>,
- this.widgets.message[0], true);
-
- if (action === this._echoLine && !(flags & this.FORCE_MULTILINE)
- && !(dactyl.fullyInitialized && this.widgets.mowContainer.collapsed)) {
+ // So complicated...
+ if (checkSingleLine() && !this.widgets.mowContainer.collapsed) {
highlightGroup += " Message";
- action = mow.closure.echo;
+ action = mow.bound.echo;
+ }
+ else if (!checkSingleLine() && this.widgets.mowContainer.collapsed) {
+ if (this._lastEcho && this.widgets.message && this.widgets.message[1] == this._lastEcho.msg) {
+ if (!(this._lastEcho.flags & this.APPEND_TO_MESSAGES))
+ appendToMessages(this._lastEcho.data);
+
+ mow.echo(
+ ["span", { highlight: "Message" },
+ ["span", { highlight: "WarningMsg" },
+ _("commandline.moreMessages", this.hiddenMessages + 1) + " "],
+ this._lastEcho.msg],
+ this.widgets.message[0], true);
+
+ this.hiddenMessages = 0;
+ }
+ }
+ else if (this._lastEcho && this.widgets.message && this.widgets.message[1] == this._lastEcho.msg) {
+ if (!(this._lastEcho.flags & this.APPEND_TO_MESSAGES))
+ appendToMessages(this._lastEcho.data);
+ if (checkSingleLine() && !(flags & this.APPEND_TO_MESSAGES))
+ appendToMessages(data);
+
+ flags |= this.APPEND_TO_MESSAGES;
+ this.hiddenMessages++;
}
- this._lastEcho = (action == this._echoLine) && data;
+ this._lastEcho = checkSingleLine() && { flags: flags, msg: data, data: arguments[0] };
}
this._lastClearable = action === this._echoLine && String(data);
this._lastEchoTime = (flags & this.FORCE_SINGLELINE) && Date.now();
if (action)
- action.call(this, data, highlightGroup, single);
+ action.call(this, data, highlightGroup, checkSingleLine());
},
_lastEchoTime: 0,
* pop at any time to close the prompt.
*
* @param {string} prompt The input prompt to use.
- * @param {function(string)} callback
* @param {Object} extra
* @... {function} onChange - A function to be called with the current
* input every time it changes.
* @... {string} default - The initial value that will be returned
* if the user presses <CR> straightaway. @default ""
*/
- input: function _input(prompt, callback, extra) {
- extra = extra || {};
+ input: promises.withCallbacks(function _input([callback, reject], prompt, extra={}, thing={}) {
+ if (callable(extra))
+ // Deprecated.
+ [callback, extra] = [extra, thing];
- CommandPromptMode(prompt, update({ onSubmit: callback }, extra)).open();
- },
+ CommandPromptMode(prompt, update({ onSubmit: callback, onCancel: reject }, extra)).open();
+ }),
readHeredoc: function readHeredoc(end) {
- let args;
- commandline.inputMultiline(end, function (res) { args = res; });
- util.waitFor(function () args !== undefined);
- return args;
+ return util.waitFor(commandline.inputMultiline(end));
},
/**
* callback with that string as a parameter.
*
* @param {string} end
- * @param {function(string)} callback
+ * @returns {Promise<string>}
*/
// FIXME: Buggy, especially when pasting.
- inputMultiline: function inputMultiline(end, callback) {
+ inputMultiline: promises.withCallbacks(function inputMultiline([callback], end) {
let cmd = this.command;
let self = {
end: "\n" + end + "\n",
this._autosizeMultilineInputWidget();
this.timeout(function () { dactyl.focus(this.widgets.multilineInput); }, 10);
- },
+ }),
get commandMode() this.commandSession && isinstance(modes.main, modes.COMMAND_LINE),
events: update(
iter(CommandMode.prototype.events).map(
- function ([event, handler]) [
+ ([event, handler]) => [
event, function (event) {
if (this.commandMode)
handler.call(this.commandSession, event);
updateOutputHeight: deprecated("mow.resize", function updateOutputHeight(open, extra) mow.resize(open, extra)),
- withOutputToString: function withOutputToString(fn, self) {
+ withOutputToString: function withOutputToString(fn, self, ...args) {
dactyl.registerObserver("echoLine", observe, true);
dactyl.registerObserver("echoMultiline", observe, true);
}
this.savingOutput = true;
- dactyl.trapErrors.apply(dactyl, [fn, self].concat(Array.slice(arguments, 2)));
+ dactyl.trapErrors.apply(dactyl, [fn, self].concat(args));
this.savingOutput = false;
- return output.map(function (elem) elem instanceof Node ? DOM.stringify(elem) : elem)
+ return output.map(elem => elem instanceof Node ? DOM.stringify(elem) : elem)
.join("\n");
}
}, {
save: function save() {
if (events.feedingKeys)
return;
+
let str = this.input.value;
if (/^\s*$/.test(str))
return;
- this.store = this.store.filter(function (line) (line.value || line) != str);
- dactyl.trapErrors(function () {
- this.store.push({ value: str, timestamp: Date.now()*1000, privateData: this.checkPrivate(str) });
- }, this);
- this.store = this.store.slice(Math.max(0, this.store.length - options["history"]));
+
+ let privateData = this.checkPrivate(str);
+ if (privateData == "never-save")
+ return;
+
+ let store = Array.filter(this.store, line => (line.value || line) != str);
+ dactyl.trapErrors(
+ () => store.push({ value: str, timestamp: Date.now() * 1000, privateData: privateData }));
+ this.store = store.slice(Math.max(0, store.length - options["history"]));
},
/**
* @property {function} Returns whether a data item should be
this.itemList = commandline.completionList;
this.itemList.open(this.context);
- dactyl.registerObserver("events.doneFeeding", this.closure.onDoneFeeding, true);
+ dactyl.registerObserver("events.doneFeeding", this.bound.onDoneFeeding, true);
this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) {
if (events.feedingKeys && !tabPressed)
},
get activeContexts() this.context.contextList
- .filter(function (c) c.items.length || c.incomplete),
+ .filter(c => c.items.length || c.incomplete),
/**
* Returns the current completion string relative to the
* called.
*/
cleanup: function cleanup() {
- dactyl.unregisterObserver("events.doneFeeding", this.closure.onDoneFeeding);
+ dactyl.unregisterObserver("events.doneFeeding", this.bound.onDoneFeeding);
this.previewClear();
this.tabTimer.reset();
* @default {@link #selected}
* @returns {object}
*/
- getItem: function getItem(tuple) {
- tuple = tuple || this.selected;
- return tuple && tuple[0] && tuple[0].items[tuple[1]];
- },
+ getItem: function getItem(tuple=this.selected)
+ tuple && tuple[0] && tuple[0].items[tuple[1]],
/**
* Returns a tuple representing the next item, at the given
substring = substring.substr(value.length);
this.removeSubstring = substring;
- let node = DOM.fromXML(<span highlight="Preview">{substring}</span>,
- document);
+ let node = DOM.fromJSON(["span", { highlight: "Preview" }, substring],
+ document);
this.withSavedValues(["caret"], function () {
this.editor.insertNode(node, this.editor.rootElement, 1);
* @default 1
* @param {boolean} fromTab If true, this function was
* called by {@link #tab}.
+ * @default false
* @private
*/
- select: function select(idx, count, fromTab) {
- count = count || 1;
-
+ select: function select(idx, count=1, fromTab=false) {
switch (idx) {
case this.UP:
case this.DOWN:
return arg;
}
}, {
- commands: function init_commands() {
+ commands: function initCommands() {
[
{
name: "ec[ho]",
commandline.echo(message.message, message.highlight, commandline.FORCE_SINGLELINE);
}
else if (commandline._messageHistory.length > 1) {
- XML.ignoreWhitespace = false;
commandline.commandOutput(
- template.map(commandline._messageHistory.messages, function (message)
- <div highlight={message.highlight + " Message"}>{message.message}</div>));
+ template.map(commandline._messageHistory.messages, message =>
+ ["div", { highlight: message.highlight + " Message" },
+ message.message]));
}
},
{ argCount: "0" });
commands.add(["sil[ent]"],
"Run a command silently",
function (args) {
- commandline.runSilently(function () commands.execute(args[0] || "", null, true));
+ commandline.runSilently(() => { commands.execute(args[0] || "", null, true); });
}, {
completer: function (context) completion.ex(context),
literal: 0,
bases: [modes.INSERT]
});
},
- mappings: function init_mappings() {
+ mappings: function initMappings() {
mappings.add([modes.COMMAND],
[":"], "Enter Command Line mode",
text = text.substring(1, index);
modes.pop();
- return function () self.callback.call(commandline, text);
+ return () => self.callback.call(commandline, text);
}
return Events.PASS;
});
- let bind = function bind()
- mappings.add.apply(mappings, [[modes.COMMAND_LINE]].concat(Array.slice(arguments)))
+ let bind = function bind(...args) mappings.add.apply(mappings, [[modes.COMMAND_LINE]].concat(args));
bind(["<Esc>", "<C-[>"], "Stop waiting for completions or exit Command Line mode",
function ({ self }) {
bind(["<C-]>", "<C-5>"], "Expand command line abbreviation",
function () { editor.expandAbbreviation(modes.COMMAND_LINE); });
},
- options: function init_options() {
+ options: function initOptions() {
options.add(["history", "hi"],
"Number of Ex commands and search patterns to store in the command-line history",
"number", 500,
"number", 100,
{ validator: function (value) value >= 0 });
},
- sanitizer: function init_sanitizer() {
+ sanitizer: function initSanitizer() {
sanitizer.addItem("commandline", {
description: "Command-line and search history",
persistent: true,
let store = commandline._store;
for (let [k, v] in store) {
if (k == "command")
- store.set(k, v.filter(function (item)
+ store.set(k, v.filter(item =>
!(timespan.contains(item.timestamp) && (!host || commands.hasDomain(item.value, host)))));
else if (!host)
- store.set(k, v.filter(function (item) !timespan.contains(item.timestamp)));
+ store.set(k, v.filter(item => !timespan.contains(item.timestamp)));
}
}
});
sanitizer.addItem("history", {
action: function (timespan, host) {
commandline._store.set("command",
- commandline._store.get("command", []).filter(function (item)
+ commandline._store.get("command", []).filter(item =>
!(timespan.contains(item.timestamp) && (host ? commands.hasDomain(item.value, host)
: item.privateData))));
- commandline._messageHistory.filter(function (item) !timespan.contains(item.timestamp * 1000) ||
- !item.domains && !item.privateData ||
- host && (!item.domains || !item.domains.some(function (d) util.isSubdomain(d, host))));
+ commandline._messageHistory.filter(item =>
+ ( !timespan.contains(item.timestamp * 1000)
+ || !item.domains && !item.privateData
+ || host && ( !item.domains
+ || !item.domains.some(d => util.isSubdomain(d, host)))));
}
});
sanitizer.addItem("messages", {
description: "Saved :messages",
action: function (timespan, host) {
- commandline._messageHistory.filter(function (item) !timespan.contains(item.timestamp * 1000) ||
- host && (!item.domains || !item.domains.some(function (d) util.isSubdomain(d, host))));
+ commandline._messageHistory.filter(item =>
+ ( !timespan.contains(item.timestamp * 1000)
+ || host && ( !item.domains
+ || !item.domains.some(d => util.isSubdomain(d, host)))));
}
});
}
this.resize(flags);
}, this);
- DOM(this.win).resize(this._onResize.closure.tell);
+ DOM(this.win).resize(this._onResize.bound.tell);
},
- get rootXML() <e4x>
- <div highlight="Normal" style="white-space: nowrap" key="root">
- <div key="wrapper">
- <div highlight="Completions" key="noCompletions"><span highlight="Title">{_("completion.noCompletions")}</span></div>
- <div key="completions"/>
- </div>
+ get rootXML()
+ ["div", { highlight: "Normal", style: "white-space: nowrap", key: "root" },
+ ["div", { key: "wrapper" },
+ ["div", { highlight: "Completions", key: "noCompletions" },
+ ["span", { highlight: "Title" },
+ _("completion.noCompletions")]],
+ ["div", { key: "completions" }]],
- <div highlight="Completions">{
- template.map(util.range(0, options["maxitems"] * 2), function (i)
- <div highlight="CompItem NonText"><li>~</li></div>)
- }</div>
- </div>
- </e4x>.elements(),
+ ["div", { highlight: "Completions" },
+ template.map(util.range(0, options["maxitems"] * 2), i =>
+ ["div", { highlight: "CompItem NonText" },
+ "~"])]],
- get itemCount() this.context.contextList.reduce(function (acc, ctxt) acc + ctxt.items.length, 0),
+ get itemCount() this.context.contextList
+ .reduce((acc, ctxt) => acc + ctxt.items.length, 0),
get visible() !this.container.collapsed,
set visible(val) this.container.collapsed = !val,
get activeGroups() this.context.contextList
- .filter(function (c) c.items.length || c.message || c.incomplete)
+ .filter(c => c.items.length || c.message || c.incomplete)
.map(this.getGroup, this),
get selected() let (g = this.selectedGroup) g && g.selectedIdx != null
if (start < 0 || start >= this.itemCount)
return null;
- group = array.nth(groups, function (g) let (i = start - g.offsets.start) i >= 0 && i < g.itemCount, 0)
+ group = groups.find(g => let (i = start - g.offsets.start) i >= 0 && i < g.itemCount);
return [group.context, start - group.offsets.start];
},
// We need to collect all of the rescrolling functions in
// one go, as the height calculation that they need to do
- // would force a reflow after each DOM modification.
- this.activeGroups.filter(function (g) !g.collapsed)
- .map(function (g) g.rescrollFunc)
+ // would force an expensive reflow after each call due to
+ // DOM modifications, otherwise.
+ this.activeGroups.filter(g => !g.collapsed)
+ .map(g => g.rescrollFunc)
.forEach(call);
if (!this.selected)
let off = group.getOffset(idx);
start = Math.constrain(start,
- off + Math.min(this.CONTEXT_LINES, group.itemCount - idx + group.offsets.end)
+ off + Math.min(this.CONTEXT_LINES,
+ group.itemCount - idx + group.offsets.end)
- this.maxItems + 1,
- off - Math.min(this.CONTEXT_LINES, idx + group.offsets.start));
+ off - Math.min(this.CONTEXT_LINES,
+ idx + group.offsets.start));
}
let count = this.maxItems;
getGroup: function getGroup(context)
context instanceof ItemList.Group ? context
: context && context.getCache("itemlist-group",
- bind("Group", ItemList, this, context)),
+ () => ItemList.Group(this, context)),
getOffset: function getOffset(tuple) tuple && this.getGroup(tuple[0]).getOffset(tuple[1])
}, {
},
get rootXML()
- <div key="root" highlight="CompGroup">
- <div highlight="Completions">
- { this.context.createRow(this.context.title || [], "CompTitle") }
- </div>
- <div highlight="CompTitleSep"/>
- <div key="contents">
- <div key="up" highlight="CompLess"/>
- <div key="message" highlight="CompMsg">{this.context.message}</div>
- <div key="itemsContainer" class="completion-items-container">
- <div key="items" highlight="Completions"/>
- </div>
- <div key="waiting" highlight="CompMsg">{ItemList.WAITING_MESSAGE}</div>
- <div key="down" highlight="CompMore"/>
- </div>
- </div>,
+ ["div", { key: "root", highlight: "CompGroup" },
+ ["div", { highlight: "Completions" },
+ this.context.createRow(this.context.title || [], "CompTitle")],
+ ["div", { highlight: "CompTitleSep" }],
+ ["div", { key: "contents" },
+ ["div", { key: "up", highlight: "CompLess" }],
+ ["div", { key: "message", highlight: "CompMsg" },
+ this.context.message || []],
+ ["div", { key: "itemsContainer", class: "completion-items-container" },
+ ["div", { key: "items", highlight: "Completions" }]],
+ ["div", { key: "waiting", highlight: "CompMsg" },
+ ItemList.WAITING_MESSAGE],
+ ["div", { key: "down", highlight: "CompMore" }]]],
get doc() this.parent.doc,
get win() this.parent.win,
container.scrollTop = scroll;
if (scrollY != null)
win.scrollTo(0, Math.max(scrollY, 0));
- }
+ };
},
/**
this.nodes = {};
this.generatedRange = ItemList.Range(0, 0);
- DOM.fromXML(this.rootXML, this.doc, this.nodes);
+ DOM.fromJSON(this.rootXML, this.doc, this.nodes);
},
/**
DOM(this.nodes.items).empty();
if (this.context.message)
- DOM(this.nodes.message).empty().append(<>{this.context.message}</>);
+ DOM(this.nodes.message).empty()
+ .append(DOM.fromJSON(this.context.message, this.doc));
- if (!this.selectedIdx > this.itemCount)
+ if (this.selectedIdx > this.itemCount)
this.selectedIdx = null;
},
first = row;
let container = DOM(this.nodes.items);
- let before = first ? DOM(first).closure.before
- : DOM(this.nodes.items).closure.append;
+ let before = first ? DOM(first).bound.before
+ : DOM(this.nodes.items).bound.append;
for (let [i, row] in this.context.getRows(range.start, range.end,
this.doc)) {
})
});
-// vim: set fdm=marker sw=4 ts=4 et:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et: