diff --git a/common/content/editor.js b/common/content/editor.js index 6a28e3c4..895269bb 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -520,8 +520,10 @@ var Editor = Module("editor", { preExecute: function preExecute(args) { if (editor.editor) editor.editor.beginTransaction(); + editor.inEditMap = true; }, postExecute: function preExecute(args) { + editor.inEditMap = false; if (editor.editor) editor.editor.endTransaction(); }, @@ -703,19 +705,25 @@ var Editor = Module("editor", { mappings.add([modes.TEXT_EDIT], key, desc, - function ({ count, motion }) { + function ({ command, count, motion }) { let start = editor.selectionRange.cloneRange(); modes.push(modes.OPERATOR, null, { + forCommand: command, + count: count, leave: function leave(stack) { if (stack.push || stack.fromEscape) return; - let range = RangeFind.union(start, editor.selectionRange); - editor.selectionRange = select ? range : start; - doTxn(range, editor); + editor.withSavedValues(["inEditMap"], function () { + this.inEditMap = true; + + let range = RangeFind.union(start, editor.selectionRange); + editor.selectionRange = select ? range : start; + doTxn(range, editor); + }); modes.delay(function () { if (mode) @@ -737,7 +745,7 @@ var Editor = Module("editor", { addMotionMap(["d", "x"], "Delete text", true, function (editor) { editor.editor.cut(); }); addMotionMap(["c"], "Change text", true, function (editor) { editor.editor.cut(); }, modes.INSERT); - addMotionMap(["y"], "Yank text", false, function (editor, range) { dactyl.clipboardWrite(DOM.stringify(range)) }); + addMotionMap(["y"], "Yank text", false, function (editor, range) { dactyl.clipboardWrite(String(range)) }); addMotionMap(["gu"], "Lowercase text", false, function (editor, range) { @@ -749,6 +757,20 @@ var Editor = Module("editor", { editor.mungeRange(range, String.toLocaleUpperCase); }); + mappings.add([modes.OPERATOR], + ["c", "d", "y"], "Select the entire line", + function ({ command, count }) { + dactyl.assert(command == modes.getStack(0).params.forCommand); + editor.executeCommand("cmd_beginLine", 1); + editor.executeCommand("cmd_selectLineNext", count || 1); + let range = editor.selectionRange; + if (command == "c" && !range.collapsed) // Hack. + if (range.endContainer instanceof Text && + range.endContainer.textContent[range.endOffset - 1] == "\n") + editor.executeCommand("cmd_selectCharPrevious", 1); + }, + { count: true, type: "operator" }); + let bind = function bind(names, description, action, params) mappings.add([modes.INPUT], names, description, action, update({ type: "editor" }, params)); diff --git a/common/content/events.js b/common/content/events.js index fdfa231b..3bba8ef8 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -909,6 +909,10 @@ var Events = Module("events", { }), onSelectionChange: function onSelectionChange(event) { + // Ignore selection events caused by editor commands. + if (editor.inEditMap || modes.main == modes.OPERATOR) + return; + let controller = document.commandDispatcher.getControllerForCommand("cmd_copy"); let couldCopy = controller && controller.isCommandEnabled("cmd_copy"); diff --git a/pentadactyl/NEWS b/pentadactyl/NEWS index 8fc9ef3b..6340b4d7 100644 --- a/pentadactyl/NEWS +++ b/pentadactyl/NEWS @@ -43,7 +43,8 @@ - Crude regular expression search is supported. [b8] - New searches now start within the current viewport where possible. [b8] • Text editing improvements, including: - - Added t_gu, t_gU, and v_o. [b8] + - Added t_gu, t_gU, and v_o mappings. [b8] + - Added o_c, o_d, and o_y mappings. [b8] - Added operator modes and proper first class motion maps. [b8] - Improved undo support for most mappings. [b8] • General completion improvements