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) {
|
||||
var toExecute;
|
||||
var success = false;
|
||||
var commands = this.$editor.commands;
|
||||
|
||||
for (var i = this.$handlers.length; i--;) {
|
||||
toExecute = this.$handlers[i].handleKeyboard(
|
||||
this.$data, hashId, keyString, keyCode, e
|
||||
);
|
||||
if (toExecute && toExecute.command)
|
||||
if (!toExecute || !toExecute.command)
|
||||
continue;
|
||||
|
||||
// allow keyboardHandler to consume keys
|
||||
if (toExecute.command == "null") {
|
||||
success = toExecute.passEvent != true;
|
||||
} else {
|
||||
success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
|
||||
}
|
||||
// do not stop input events to not break repeating
|
||||
if (success && e && hashId != -1)
|
||||
event.stopEvent(e);
|
||||
if (success)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!toExecute || !toExecute.command)
|
||||
return false;
|
||||
|
||||
var success = false;
|
||||
var commands = this.$editor.commands;
|
||||
|
||||
// allow keyboardHandler to consume keys
|
||||
if (toExecute.command != "null")
|
||||
success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
|
||||
else
|
||||
success = toExecute.passEvent != true;
|
||||
|
||||
// do not stop input events to not break repeating
|
||||
if (success && e && hashId != -1)
|
||||
event.stopEvent(e);
|
||||
|
||||
return success;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -96,12 +96,14 @@ exports.handler = {
|
|||
key = data.inputChar;
|
||||
}
|
||||
|
||||
if (hashId == -1 || hashId == 1) {
|
||||
if (hashId == -1 || hashId == 1 || hashId == 0 && key.length > 1) {
|
||||
if (cmds.inputBuffer.idle && startCommands[key])
|
||||
return startCommands[key];
|
||||
return {
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -133,6 +133,18 @@ var actions = exports.actions = {
|
|||
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": {
|
||||
fn: function(editor, range, count, param) {
|
||||
var options = editor.getLastSearchOptions();
|
||||
|
|
@ -288,7 +300,17 @@ var actions = exports.actions = {
|
|||
if (previous) // If there is a previous action
|
||||
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 = {
|
||||
|
|
@ -305,6 +327,7 @@ var inputBuffer = exports.inputBuffer = {
|
|||
lastInsertCommands: [],
|
||||
|
||||
push: function(editor, ch, keyId) {
|
||||
var isKeyHandled = true;
|
||||
this.idle = false;
|
||||
var wObj = this.waitingForParam;
|
||||
if (wObj) {
|
||||
|
|
@ -369,6 +392,7 @@ var inputBuffer = exports.inputBuffer = {
|
|||
this.exec(editor, { operator: this.operator }, ch);
|
||||
}
|
||||
else {
|
||||
isKeyHandled = ch.length == 1;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
|
|
@ -379,9 +403,10 @@ var inputBuffer = exports.inputBuffer = {
|
|||
} else if (this.status) {
|
||||
this.status = "";
|
||||
} else {
|
||||
return;
|
||||
return isKeyHandled;
|
||||
}
|
||||
editor._emit("changeStatus");
|
||||
return isKeyHandled;
|
||||
},
|
||||
|
||||
waitForParam: function(cmd) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (c) 2010, Ajax.org B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* * Neither the name of Ajax.org B.V. nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
|
|
@ -222,7 +222,11 @@ module.exports = {
|
|||
|
||||
"l": {
|
||||
nav: function(editor) {
|
||||
editor.navigateRight();
|
||||
var pos = editor.getCursorPosition();
|
||||
var col = pos.column;
|
||||
var lineLen = editor.session.getLine(pos.row).length;
|
||||
if (lineLen && col !== lineLen)
|
||||
editor.navigateRight();
|
||||
},
|
||||
sel: function(editor) {
|
||||
var pos = editor.getCursorPosition();
|
||||
|
|
@ -382,7 +386,7 @@ module.exports = {
|
|||
var column = util.getRightNthChar(editor, cursor, param, count || 1);
|
||||
|
||||
if (typeof column === "number") {
|
||||
cursor.column += column + (isSel ? 2 : 1);
|
||||
cursor.column += column + (isSel ? 2 : 1);
|
||||
return cursor;
|
||||
}
|
||||
}
|
||||
|
|
@ -559,7 +563,7 @@ module.exports = {
|
|||
while(row < l && !/\S/.test(session.getLine(row)))
|
||||
row++;
|
||||
while(/\S/.test(session.getLine(row)))
|
||||
row++;
|
||||
row++;
|
||||
return {column: 0, row: row};
|
||||
}),
|
||||
"ctrl-d": {
|
||||
|
|
@ -575,12 +579,38 @@ module.exports = {
|
|||
nav: function(editor, range, count, param) {
|
||||
editor.selection.clearSelection();
|
||||
keepScrollPosition(editor, editor.gotoPageUp);
|
||||
|
||||
},
|
||||
sel: function(editor, range, count, param) {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ oop.inherits(Worker, Mirror);
|
|||
ruleNames.forEach(function(x) {
|
||||
delete all[x];
|
||||
});
|
||||
console.log(all)
|
||||
|
||||
this.ruleset = all;
|
||||
}
|
||||
this.doc.getValue() && this.deferredUpdate.schedule(100);
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ var normalizeModule = function(parentId, moduleName) {
|
|||
// normalize relative requires
|
||||
if (moduleName.charAt(0) == ".") {
|
||||
var base = parentId.split("/").slice(0, -1).join("/");
|
||||
var moduleName = base + "/" + moduleName;
|
||||
moduleName = base + "/" + moduleName;
|
||||
|
||||
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
||||
var previous = moduleName;
|
||||
var moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
||||
moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +41,8 @@ var require = function(parentId, id) {
|
|||
if (!id.charAt)
|
||||
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];
|
||||
if (module) {
|
||||
if (!module.initialized) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue