-// Copyright (c) 2008-2011 Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
//
// 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 */
}, this);
},
- defaultRegister: "*",
+ defaultRegister: "*+",
selectionRegisters: {
"*": "selection",
if (name == null)
name = editor.currentRegister || editor.defaultRegister;
+ name = String(name)[0];
if (name == '"')
name = 0;
if (name == "_")
var res = null;
- else if (Set.has(this.selectionRegisters, name))
+ else if (hasOwnProperty(this.selectionRegisters, name))
res = { text: dactyl.clipboardRead(this.selectionRegisters[name]) || "" };
else if (!/^[0-9]$/.test(name))
res = this.registers.get(name);
value = DOM.stringify(value);
value = { text: value, isLine: modes.extended & modes.LINE, timestamp: Date.now() * 1000 };
- if (name == '"')
- name = 0;
- if (name == "_")
- ;
- else if (Set.has(this.selectionRegisters, name))
- dactyl.clipboardWrite(value.text, verbose, this.selectionRegisters[name]);
- else if (!/^[0-9]$/.test(name))
- this.registers.set(name, value);
- else {
- this.registerRing.insert(value, name);
- this.registerRing.truncate(10);
+ for (let n of String(name)) {
+ if (n == '"')
+ n = 0;
+ if (n == "_")
+ ;
+ else if (hasOwnProperty(this.selectionRegisters, n))
+ dactyl.clipboardWrite(value.text, verbose, this.selectionRegisters[n]);
+ else if (!/^[0-9]$/.test(n))
+ this.registers.set(n, value);
+ else {
+ this.registerRing.insert(value, n);
+ this.registerRing.truncate(10);
+ }
}
},
this.setRegister(name, range);
},
- cut: function cut(range, name) {
+ cut: function cut(range, name, noStrip) {
if (range)
this.selectedRange = range;
if (!this.selection.isCollapsed)
this.setRegister(name, this.selection);
- this.editor.deleteSelection(0);
+ this.editor.deleteSelection(0, this.editor[noStrip ? "eNoStrip" : "eStrip"]);
},
paste: function paste(name) {
// Skip to any requested offset.
count = Math.abs(offset);
- Editor.extendRange(range, offset > 0, { test: function (c) !!count-- }, true);
+ Editor.extendRange(range, offset > 0,
+ { test: c => !!count-- },
+ true);
range.collapse(offset < 0);
return range;
textBox = null;
let line, column;
- let keepFocus = modes.stack.some(function (m) isinstance(m.main, modes.COMMAND_LINE));
+ let keepFocus = modes.stack.some(m => isinstance(m.main, modes.COMMAND_LINE));
if (!forceEditing && textBox && textBox.type == "password") {
- commandline.input(_("editor.prompt.editPassword") + " ",
- function (resp) {
+ commandline.input(_("editor.prompt.editPassword") + " ")
+ .then(function (resp) {
if (resp && resp.match(/^y(es)?$/i))
editor.editFieldExternally(true);
});
var editor_ = window.GetCurrentEditor ? GetCurrentEditor()
: Editor.getEditor(document.commandDispatcher.focusedWindow);
dactyl.assert(editor_);
- text = Array.map(editor_.rootElement.childNodes, function (e) DOM.stringify(e, true)).join("");
+ text = Array.map(editor_.rootElement.childNodes,
+ e => DOM.stringify(e, true))
+ .join("");
if (!editor_.selection.rangeCount)
var sel = "";
column = 1 + pre.replace(/[^]*\n/, "").length;
let origGroup = DOM(textBox).highlight.toString();
- let cleanup = util.yieldable(function cleanup(error) {
+ let cleanup = promises.task(function cleanup(error) {
if (timer)
timer.cancel();
DOM(textBox).highlight.remove("EditorEditing");
if (!keepFocus)
dactyl.focus(textBox);
+
for (let group in values(blink.concat(blink, ""))) {
highlight.highlightNode(textBox, origGroup + " " + group);
- yield 100;
+
+ yield promises.sleep(100);
}
}
});
}
try {
- var tmpfile = io.createTempFile();
+ var tmpfile = io.createTempFile("txt", "." + buffer.uri.host);
if (!tmpfile)
throw Error(_("io.cantCreateTempFile"));
return DOM(elem).editor;
}
}, {
- modes: function init_modes() {
+ modes: function initModes() {
modes.addMode("OPERATOR", {
char: "o",
description: "Mappings which move the cursor",
bases: [modes.INSERT]
});
},
- commands: function init_commands() {
+ commands: function initCommands() {
commands.add(["reg[isters]"],
"List the contents of known registers",
function (args) {
},
{ argCount: "*" });
},
- completion: function init_completion() {
+ completion: function initCompletion() {
completion.register = function complete_register(context) {
context = context.fork("registers");
- context.keys = { text: util.identity, description: editor.closure.getRegister };
+ context.keys = { text: util.identity, description: editor.bound.getRegister };
- context.match = function (r) !this.filter || ~this.filter.indexOf(r);
+ context.match = function (r) !this.filter || this.filter.contains(r);
context.fork("clipboard", 0, this, function (ctxt) {
ctxt.match = context.match;
});
};
},
- mappings: function init_mappings() {
+ mappings: function initMappings() {
Map.types["editor"] = {
preExecute: function preExecute(args) {
function addBeginInsertModeMap(keys, commands, description) {
mappings.add([modes.TEXT_EDIT], keys, description || "",
function () {
- commands.forEach(function (cmd) { editor.executeCommand(cmd, 1) });
+ commands.forEach(function (cmd) { editor.executeCommand(cmd, 1); });
modes.push(modes.INSERT);
},
{ type: "editor" });
}
addMotionMap(["d", "x"], "Delete text", true, function (editor) { editor.cut(); });
- addMotionMap(["c"], "Change text", true, function (editor) { editor.cut(); }, modes.INSERT);
+ addMotionMap(["c"], "Change text", true, function (editor) { editor.cut(null, null, true); }, modes.INSERT);
addMotionMap(["y"], "Yank text", false, function (editor, range) { editor.copy(range); }, null, true);
addMotionMap(["gu"], "Lowercase text", false,
"<*-Home>", "<*-End>", "<*-PageUp>", "<*-PageDown>",
"<M-c>", "<M-v>", "<*-Tab>"],
"Handled by " + config.host,
- function () Events.PASS_THROUGH);
+ () => Events.PASS_THROUGH);
mappings.add([modes.INSERT],
["<Space>", "<Return>"], "Expand Insert mode abbreviation",
mappings.add([modes.TEXT_EDIT], names, description,
action, update({ type: "editor" }, params));
-
bind(["<C-a>"], "Increment the next number",
- function ({ count }) { editor.modifyNumber(count || 1) },
+ function ({ count }) { editor.modifyNumber(count || 1); },
{ count: true });
bind(["<C-x>"], "Decrement the next number",
- function ({ count }) { editor.modifyNumber(-(count || 1)) },
+ function ({ count }) { editor.modifyNumber(-(count || 1)); },
{ count: true });
// text edit mode
bind(["u"], "Undo changes",
- function (args) {
- editor.editor.undo(Math.max(args.count, 1));
+ function ({ count }) {
+ editor.editor.undo(Math.max(count, 1));
editor.deselect();
},
{ count: true, noTransaction: true });
bind(["<C-r>"], "Redo undone changes",
- function (args) {
- editor.editor.redo(Math.max(args.count, 1));
+ function ({ count }) {
+ editor.editor.redo(Math.max(count, 1));
editor.deselect();
},
{ count: true, noTransaction: true });
var range = editor.selectedRange;
if (range.collapsed) {
count = count || 1;
- Editor.extendRange(range, true, { test: function (c) !!count-- }, true);
+ Editor.extendRange(range, true, { test: c => !!count-- }, true);
}
editor.mungeRange(range, munger, count != null);
},
{ count: true });
- let bind = function bind() mappings.add.apply(mappings,
- [[modes.AUTOCOMPLETE]].concat(Array.slice(arguments)))
+ let bind = function bind(...args) mappings.add.apply(mappings, [[modes.AUTOCOMPLETE]].concat(args));
bind(["<Esc>"], "Return to Insert mode",
- function () Events.PASS_THROUGH);
+ () => Events.PASS_THROUGH);
bind(["<C-[>"], "Return to Insert mode",
function () { events.feedkeys("<Esc>", { skipmap: true }); });
bind(["<Up>"], "Select the previous autocomplete result",
- function () Events.PASS_THROUGH);
+ () => Events.PASS_THROUGH);
bind(["<C-p>"], "Select the previous autocomplete result",
function () { events.feedkeys("<Up>", { skipmap: true }); });
bind(["<Down>"], "Select the next autocomplete result",
- function () Events.PASS_THROUGH);
+ () => Events.PASS_THROUGH);
bind(["<C-n>"], "Select the next autocomplete result",
function () { events.feedkeys("<Down>", { skipmap: true }); });
},
- options: function init_options() {
+ options: function initOptions() {
options.add(["editor"],
"The external text editor",
"string", 'gvim -f +<line> +"sil! call cursor(0, <column>)" <file>', {
format: function (obj, value) {
- let args = commands.parseArgs(value || this.value, { argCount: "*", allowUnknownOptions: true })
- .map(util.compileMacro).filter(function (fmt) fmt.valid(obj))
- .map(function (fmt) fmt(obj));
+ let args = commands.parseArgs(value || this.value,
+ { argCount: "*", allowUnknownOptions: true })
+ .map(util.compileMacro)
+ .filter(fmt => fmt.valid(obj))
+ .map(fmt => fmt(obj));
+
if (obj["file"] && !this.has("file"))
args.push(obj["file"]);
return args;
},
- has: function (key) Set.has(util.compileMacro(this.value).seen, key),
+ has: function (key) util.compileMacro(this.value).seen.has(key),
validator: function (value) {
this.format({}, value);
- return Object.keys(util.compileMacro(value).seen).every(function (k) ["column", "file", "line"].indexOf(k) >= 0);
+ let allowed = RealSet(["column", "file", "line"]);
+ return [k for (k of util.compileMacro(value).seen)]
+ .every(k => allowed.has(k));
}
});
}
});
},
- sanitizer: function () {
+ sanitizer: function initSanitizer() {
sanitizer.addItem("registers", {
description: "Register values",
persistent: true,
}
});
-// vim: set fdm=marker sw=4 ts=4 et:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et: