fix emacs universal argument
This commit is contained in:
parent
e83252130c
commit
d09740f494
4 changed files with 30 additions and 19 deletions
|
|
@ -28,9 +28,8 @@ var StatusBar = function(editor, parentNode) {
|
||||||
str && status.push(str, separator || "|");
|
str && status.push(str, separator || "|");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editor.$vimModeHandler)
|
add(editor.keyBinding.getStatusText(editor));
|
||||||
add(editor.$vimModeHandler.getStatusText());
|
if (editor.commands.recording)
|
||||||
else if (editor.commands.recording)
|
|
||||||
add("REC");
|
add("REC");
|
||||||
|
|
||||||
var c = editor.selection.lead;
|
var c = editor.selection.lead;
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,7 @@ exports.handler.detach = function(editor) {
|
||||||
editor.commands.removeCommands(commands);
|
editor.commands.removeCommands(commands);
|
||||||
editor.removeEventListener('copy', this.onCopy);
|
editor.removeEventListener('copy', this.onCopy);
|
||||||
editor.removeEventListener('paste', this.onPaste);
|
editor.removeEventListener('paste', this.onPaste);
|
||||||
|
editor.$emacsModeHandler = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
var $kbSessionChange = function(e) {
|
var $kbSessionChange = function(e) {
|
||||||
|
|
@ -205,7 +206,7 @@ exports.handler.onCopy = function(e, editor) {
|
||||||
if (editor.$handlesEmacsOnCopy) return;
|
if (editor.$handlesEmacsOnCopy) return;
|
||||||
editor.$handlesEmacsOnCopy = true;
|
editor.$handlesEmacsOnCopy = true;
|
||||||
exports.handler.commands.killRingSave.exec(editor);
|
exports.handler.commands.killRingSave.exec(editor);
|
||||||
delete editor.$handlesEmacsOnCopy;
|
editor.$handlesEmacsOnCopy = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.handler.onPaste = function(e, editor) {
|
exports.handler.onPaste = function(e, editor) {
|
||||||
|
|
@ -238,12 +239,22 @@ exports.handler.bindKey = function(key, command) {
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.handler.getStatusText = function(editor, data) {
|
||||||
|
var str = "";
|
||||||
|
if (data.count)
|
||||||
|
str += data.count;
|
||||||
|
if (data.keyChain)
|
||||||
|
str += " " + data.keyChain
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|
||||||
exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
|
exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
|
||||||
// if keyCode == -1 a non-printable key was pressed, such as just
|
// if keyCode == -1 a non-printable key was pressed, such as just
|
||||||
// control. Handling those is currently not supported in this handler
|
// control. Handling those is currently not supported in this handler
|
||||||
if (keyCode === -1) return undefined;
|
if (keyCode === -1) return undefined;
|
||||||
|
|
||||||
var editor = data.editor;
|
var editor = data.editor;
|
||||||
|
editor._signal("changeStatus");
|
||||||
// insertstring data.count times
|
// insertstring data.count times
|
||||||
if (hashId == -1) {
|
if (hashId == -1) {
|
||||||
editor.pushEmacsMark();
|
editor.pushEmacsMark();
|
||||||
|
|
@ -254,24 +265,17 @@ exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == "\x00") return undefined;
|
|
||||||
|
|
||||||
var modifier = eMods[hashId];
|
var modifier = eMods[hashId];
|
||||||
|
|
||||||
// CTRL + number / universalArgument for setting data.count
|
// CTRL + number / universalArgument for setting data.count
|
||||||
if (modifier == "c-" || data.universalArgument) {
|
if (modifier == "c-" || data.count) {
|
||||||
var prevCount = String(data.count || 0);
|
|
||||||
var count = parseInt(key[key.length - 1]);
|
var count = parseInt(key[key.length - 1]);
|
||||||
if (typeof count === 'number' && !isNaN(count)) {
|
if (typeof count === 'number' && !isNaN(count)) {
|
||||||
data.count = parseInt(prevCount + count);
|
data.count = Math.max(data.count, 0) || 0;
|
||||||
|
data.count = 10 * data.count + count;
|
||||||
return {command: "null"};
|
return {command: "null"};
|
||||||
} else if (data.universalArgument) {
|
|
||||||
// if no number pressed use emacs defaults for universalArgument
|
|
||||||
// which is 4
|
|
||||||
data.count = 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.universalArgument = false;
|
|
||||||
|
|
||||||
// this.commandKeyBinding maps key specs like "c-p" (for CTRL + P) to
|
// this.commandKeyBinding maps key specs like "c-p" (for CTRL + P) to
|
||||||
// command objects, for lookup key needs to include the modifier
|
// command objects, for lookup key needs to include the modifier
|
||||||
|
|
@ -293,7 +297,9 @@ exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
|
||||||
if (command === "null") return {command: "null"};
|
if (command === "null") return {command: "null"};
|
||||||
|
|
||||||
if (command === "universalArgument") {
|
if (command === "universalArgument") {
|
||||||
data.universalArgument = true;
|
// if no number pressed emacs repeats action 4 times.
|
||||||
|
// minus sign is needed to allow next keypress to replace it
|
||||||
|
data.count = -4;
|
||||||
return {command: "null"};
|
return {command: "null"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -607,6 +613,7 @@ exports.handler.addCommands({
|
||||||
keyboardQuit: function(editor) {
|
keyboardQuit: function(editor) {
|
||||||
editor.selection.clearSelection();
|
editor.selection.clearSelection();
|
||||||
editor.setEmacsMark(null);
|
editor.setEmacsMark(null);
|
||||||
|
editor.keyBinding.$data.count = null;
|
||||||
},
|
},
|
||||||
focusCommandLine: function(editor, arg) {
|
focusCommandLine: function(editor, arg) {
|
||||||
if (editor.showCommandLine)
|
if (editor.showCommandLine)
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,6 @@ module.exports = {
|
||||||
assert.ok(editor.selection.isEmpty(), 'selection non-empty');
|
assert.ok(editor.selection.isEmpty(), 'selection non-empty');
|
||||||
},
|
},
|
||||||
|
|
||||||
// this.aceEditor.getSelectedText()
|
|
||||||
// this.aceEditor.selection.getAllRanges()
|
|
||||||
// lively.ide.ace.require("ace/range").Range.fromPoints(start, end)
|
|
||||||
"test: exchangePointAndMark without mark set": function() {
|
"test: exchangePointAndMark without mark set": function() {
|
||||||
initEditor('foo');
|
initEditor('foo');
|
||||||
sel.setRange(Range.fromPoints({row: 0, column: 1}, {row: 0, column: 3}));
|
sel.setRange(Range.fromPoints({row: 0, column: 1}, {row: 0, column: 3}));
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,16 @@ var KeyBinding = function(editor) {
|
||||||
this.getKeyboardHandler = function() {
|
this.getKeyboardHandler = function() {
|
||||||
return this.$handlers[this.$handlers.length - 1];
|
return this.$handlers[this.$handlers.length - 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getStatusText = function() {
|
||||||
|
var data = this.$data;
|
||||||
|
var editor = data.editor;
|
||||||
|
return this.$handlers.map(function(h) {
|
||||||
|
return h.getStatusText && h.getStatusText(editor, data) || "";
|
||||||
|
}).filter(Boolean).join(" ");
|
||||||
|
};
|
||||||
|
|
||||||
this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
|
this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) {
|
||||||
var toExecute;
|
var toExecute;
|
||||||
var success = false;
|
var success = false;
|
||||||
var commands = this.$editor.commands;
|
var commands = this.$editor.commands;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue