Merge pull request #1133 from ajaxorg/vim
[vim] allow unhandled keys to pass to the browser
This commit is contained in:
commit
117d29a4cb
6 changed files with 89 additions and 34 deletions
|
|
@ -90,30 +90,28 @@ var KeyBinding = function(editor) {
|
||||||
|
|
||||||
this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
|
this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
|
||||||
var toExecute;
|
var toExecute;
|
||||||
|
var success = false;
|
||||||
|
var commands = this.$editor.commands;
|
||||||
|
|
||||||
for (var i = this.$handlers.length; i--;) {
|
for (var i = this.$handlers.length; i--;) {
|
||||||
toExecute = this.$handlers[i].handleKeyboard(
|
toExecute = this.$handlers[i].handleKeyboard(
|
||||||
this.$data, hashId, keyString, keyCode, e
|
this.$data, hashId, keyString, keyCode, e
|
||||||
);
|
);
|
||||||
if (toExecute && toExecute.command)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!toExecute || !toExecute.command)
|
if (!toExecute || !toExecute.command)
|
||||||
return false;
|
continue;
|
||||||
|
|
||||||
var success = false;
|
|
||||||
var commands = this.$editor.commands;
|
|
||||||
|
|
||||||
// allow keyboardHandler to consume keys
|
// allow keyboardHandler to consume keys
|
||||||
if (toExecute.command != "null")
|
if (toExecute.command == "null") {
|
||||||
success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
|
|
||||||
else
|
|
||||||
success = toExecute.passEvent != true;
|
success = toExecute.passEvent != true;
|
||||||
|
} else {
|
||||||
|
success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
|
||||||
|
}
|
||||||
// do not stop input events to not break repeating
|
// do not stop input events to not break repeating
|
||||||
if (success && e && hashId != -1)
|
if (success && e && hashId != -1)
|
||||||
event.stopEvent(e);
|
event.stopEvent(e);
|
||||||
|
if (success)
|
||||||
|
break;
|
||||||
|
}
|
||||||
return success;
|
return success;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,12 +96,14 @@ exports.handler = {
|
||||||
key = data.inputChar;
|
key = data.inputChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashId == -1 || hashId == 1) {
|
if (hashId == -1 || hashId == 1 || hashId == 0 && key.length > 1) {
|
||||||
if (cmds.inputBuffer.idle && startCommands[key])
|
if (cmds.inputBuffer.idle && startCommands[key])
|
||||||
return startCommands[key];
|
return startCommands[key];
|
||||||
return {
|
return {
|
||||||
command: {
|
command: {
|
||||||
exec: function(editor) {cmds.inputBuffer.push(editor, key);}
|
exec: function(editor) {
|
||||||
|
return cmds.inputBuffer.push(editor, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // if no modifier || shift: wait for input.
|
} // if no modifier || shift: wait for input.
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,18 @@ var actions = exports.actions = {
|
||||||
editor.selection.setSelectionRange(r, true);
|
editor.selection.setSelectionRange(r, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"m": {
|
||||||
|
param: true,
|
||||||
|
fn: function(editor, range, count, param) {
|
||||||
|
var s = editor.session;
|
||||||
|
var markers = s.vimMarkers || (s.vimMarkers = {});
|
||||||
|
var c = editor.getCursorPosition();
|
||||||
|
if (!markers[param]) {
|
||||||
|
markers[param] = editor.session.doc.createAnchor(c);
|
||||||
|
}
|
||||||
|
markers[param].setPosition(c.row, c.column, true);
|
||||||
|
}
|
||||||
|
},
|
||||||
"n": {
|
"n": {
|
||||||
fn: function(editor, range, count, param) {
|
fn: function(editor, range, count, param) {
|
||||||
var options = editor.getLastSearchOptions();
|
var options = editor.getLastSearchOptions();
|
||||||
|
|
@ -288,7 +300,17 @@ var actions = exports.actions = {
|
||||||
if (previous) // If there is a previous action
|
if (previous) // If there is a previous action
|
||||||
inputBuffer.exec(editor, previous.action, previous.param);
|
inputBuffer.exec(editor, previous.action, previous.param);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ctrl-x": {
|
||||||
|
fn: function(editor, range, count, param) {
|
||||||
|
editor.modifyNumber(-(count || 1));
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ctrl-a": {
|
||||||
|
fn: function(editor, range, count, param) {
|
||||||
|
editor.modifyNumber(count || 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var inputBuffer = exports.inputBuffer = {
|
var inputBuffer = exports.inputBuffer = {
|
||||||
|
|
@ -305,6 +327,7 @@ var inputBuffer = exports.inputBuffer = {
|
||||||
lastInsertCommands: [],
|
lastInsertCommands: [],
|
||||||
|
|
||||||
push: function(editor, ch, keyId) {
|
push: function(editor, ch, keyId) {
|
||||||
|
var isKeyHandled = true;
|
||||||
this.idle = false;
|
this.idle = false;
|
||||||
var wObj = this.waitingForParam;
|
var wObj = this.waitingForParam;
|
||||||
if (wObj) {
|
if (wObj) {
|
||||||
|
|
@ -369,6 +392,7 @@ var inputBuffer = exports.inputBuffer = {
|
||||||
this.exec(editor, { operator: this.operator }, ch);
|
this.exec(editor, { operator: this.operator }, ch);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
isKeyHandled = ch.length == 1;
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,9 +403,10 @@ var inputBuffer = exports.inputBuffer = {
|
||||||
} else if (this.status) {
|
} else if (this.status) {
|
||||||
this.status = "";
|
this.status = "";
|
||||||
} else {
|
} else {
|
||||||
return;
|
return isKeyHandled;
|
||||||
}
|
}
|
||||||
editor._emit("changeStatus");
|
editor._emit("changeStatus");
|
||||||
|
return isKeyHandled;
|
||||||
},
|
},
|
||||||
|
|
||||||
waitForParam: function(cmd) {
|
waitForParam: function(cmd) {
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,10 @@ module.exports = {
|
||||||
|
|
||||||
"l": {
|
"l": {
|
||||||
nav: function(editor) {
|
nav: function(editor) {
|
||||||
|
var pos = editor.getCursorPosition();
|
||||||
|
var col = pos.column;
|
||||||
|
var lineLen = editor.session.getLine(pos.row).length;
|
||||||
|
if (lineLen && col !== lineLen)
|
||||||
editor.navigateRight();
|
editor.navigateRight();
|
||||||
},
|
},
|
||||||
sel: function(editor) {
|
sel: function(editor) {
|
||||||
|
|
@ -575,12 +579,38 @@ module.exports = {
|
||||||
nav: function(editor, range, count, param) {
|
nav: function(editor, range, count, param) {
|
||||||
editor.selection.clearSelection();
|
editor.selection.clearSelection();
|
||||||
keepScrollPosition(editor, editor.gotoPageUp);
|
keepScrollPosition(editor, editor.gotoPageUp);
|
||||||
|
|
||||||
},
|
},
|
||||||
sel: function(editor, range, count, param) {
|
sel: function(editor, range, count, param) {
|
||||||
keepScrollPosition(editor, editor.selectPageUp);
|
keepScrollPosition(editor, editor.selectPageUp);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"`": new Motion({
|
||||||
|
param: true,
|
||||||
|
handlesCount: true,
|
||||||
|
getPos: function(editor, range, count, param, isSel) {
|
||||||
|
var s = editor.session;
|
||||||
|
var marker = s.vimMarkers && s.vimMarkers[param];
|
||||||
|
if (marker) {
|
||||||
|
return marker.getPosition();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
"'": new Motion({
|
||||||
|
param: true,
|
||||||
|
handlesCount: true,
|
||||||
|
getPos: function(editor, range, count, param, isSel) {
|
||||||
|
var s = editor.session;
|
||||||
|
var marker = s.vimMarkers && s.vimMarkers[param];
|
||||||
|
if (marker) {
|
||||||
|
var pos = marker.getPosition();
|
||||||
|
var line = editor.session.getLine(pos.row);
|
||||||
|
pos.column = line.search(/\S/);
|
||||||
|
if (pos.column == -1)
|
||||||
|
pos.column = line.length;
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.backspace = module.exports.left = module.exports.h;
|
module.exports.backspace = module.exports.left = module.exports.h;
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ oop.inherits(Worker, Mirror);
|
||||||
ruleNames.forEach(function(x) {
|
ruleNames.forEach(function(x) {
|
||||||
delete all[x];
|
delete all[x];
|
||||||
});
|
});
|
||||||
console.log(all)
|
|
||||||
this.ruleset = all;
|
this.ruleset = all;
|
||||||
}
|
}
|
||||||
this.doc.getValue() && this.deferredUpdate.schedule(100);
|
this.doc.getValue() && this.deferredUpdate.schedule(100);
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@ var normalizeModule = function(parentId, moduleName) {
|
||||||
// normalize relative requires
|
// normalize relative requires
|
||||||
if (moduleName.charAt(0) == ".") {
|
if (moduleName.charAt(0) == ".") {
|
||||||
var base = parentId.split("/").slice(0, -1).join("/");
|
var base = parentId.split("/").slice(0, -1).join("/");
|
||||||
var moduleName = base + "/" + moduleName;
|
moduleName = base + "/" + moduleName;
|
||||||
|
|
||||||
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
||||||
var previous = moduleName;
|
var previous = moduleName;
|
||||||
var moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ var require = function(parentId, id) {
|
||||||
if (!id.charAt)
|
if (!id.charAt)
|
||||||
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
|
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
|
||||||
|
|
||||||
var id = normalizeModule(parentId, id);
|
id = normalizeModule(parentId, id);
|
||||||
|
|
||||||
var module = require.modules[id];
|
var module = require.modules[id];
|
||||||
if (module) {
|
if (module) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue