X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fcontent%2Feditor.js;h=01a25ebddb60346e5412d735ae2422b5716a99e1;hb=3d837eb266a3a01d424192aa4ec1a167366178c5;hp=262391ece5c0696b42388e4cc65c8082146a2764;hpb=9044153cb63835e39b9de8ec4ade237c03e3888a;p=dactyl.git diff --git a/common/content/editor.js b/common/content/editor.js index 262391e..01a25eb 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -3,7 +3,7 @@ // // 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 */ @@ -168,14 +168,14 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { 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) { @@ -280,7 +280,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { } }, - findChar: function findNumber(key, count, backward, offset) { + findChar: function findChar(key, count, backward, offset) { count = count || 1; // XXX ? offset = (offset || 0) - !!backward; @@ -455,7 +455,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { if (textBox) { textBox.value = val; - if (false) { + if (true) { let elem = DOM(textBox); elem.attrNS(NS, "modifiable", true) .style.MozUserInput; @@ -470,7 +470,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { } try { - var tmpfile = io.createTempFile(); + var tmpfile = io.createTempFile("txt", "." + buffer.uri.host); if (!tmpfile) throw Error(_("io.cantCreateTempFile")); @@ -688,7 +688,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { return DOM(elem).editor; } }, { - modes: function init_modes() { + modes: function initModes() { modes.addMode("OPERATOR", { char: "o", description: "Mappings which move the cursor", @@ -745,7 +745,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { bases: [modes.INSERT] }); }, - commands: function init_commands() { + commands: function initCommands() { commands.add(["reg[isters]"], "List the contents of known registers", function (args) { @@ -753,7 +753,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { }, { 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 }; @@ -777,20 +777,22 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { }); }; }, - mappings: function init_mappings() { + mappings: function initMappings() { Map.types["editor"] = { preExecute: function preExecute(args) { if (editor.editor && !this.editor) { this.editor = editor.editor; - this.editor.beginTransaction(); + if (!this.noTransaction) + this.editor.beginTransaction(); } editor.inEditMap = true; }, postExecute: function preExecute(args) { editor.inEditMap = false; if (this.editor) { - this.editor.endTransaction(); + if (!this.noTransaction) + this.editor.endTransaction(); this.editor = null; } }, @@ -868,7 +870,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { 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" }); @@ -1033,7 +1035,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { } 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, @@ -1146,29 +1148,28 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { mappings.add([modes.TEXT_EDIT], names, description, action, update({ type: "editor" }, params)); - bind([""], "Increment the next number", - function ({ count }) { editor.modifyNumber(count || 1) }, + function ({ count }) { editor.modifyNumber(count || 1); }, { count: true }); bind([""], "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.executeCommand("cmd_undo", Math.max(args.count, 1)); + function ({ count }) { + editor.editor.undo(Math.max(count, 1)); editor.deselect(); }, - { count: true }); + { count: true, noTransaction: true }); bind([""], "Redo undone changes", - function (args) { - editor.executeCommand("cmd_redo", Math.max(args.count, 1)); + function ({ count }) { + editor.editor.redo(Math.max(count, 1)); editor.deselect(); }, - { count: true }); + { count: true, noTransaction: true }); bind(["D"], "Delete characters from the cursor to the end of the line", function () { editor.executeCommand("cmd_deleteToEndOfLine"); }); @@ -1323,8 +1324,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { }, { 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([""], "Return to Insert mode", function () Events.PASS_THROUGH); @@ -1344,7 +1344,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { bind([""], "Select the next autocomplete result", function () { events.feedkeys("", { skipmap: true }); }); }, - options: function init_options() { + options: function initOptions() { options.add(["editor"], "The external text editor", "string", 'gvim -f + +"sil! call cursor(0, )" ', { @@ -1389,7 +1389,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { } }); }, - sanitizer: function () { + sanitizer: function initSanitizer() { sanitizer.addItem("registers", { description: "Register values", persistent: true, @@ -1405,4 +1405,4 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), { } }); -// vim: set fdm=marker sw=4 ts=4 et: +// vim: set fdm=marker sw=4 sts=4 ts=8 et: