1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-04 04:04:12 +01:00

Add o_c, o_d, and o_y. Fix selection mode change magic bug.

This commit is contained in:
Kris Maglione
2011-10-05 01:42:44 -04:00
parent 4722c8011e
commit 59bf923305
3 changed files with 33 additions and 6 deletions

View File

@@ -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));

View File

@@ -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");