diff --git a/lib/ace/keyboard/keybinding.js b/lib/ace/keyboard/keybinding.js index f92d1f6f..3078c2d0 100644 --- a/lib/ace/keyboard/keybinding.js +++ b/lib/ace/keyboard/keybinding.js @@ -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; }; diff --git a/lib/ace/keyboard/vim.js b/lib/ace/keyboard/vim.js index 5313e44c..7e8ec739 100644 --- a/lib/ace/keyboard/vim.js +++ b/lib/ace/keyboard/vim.js @@ -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. diff --git a/lib/ace/keyboard/vim/commands.js b/lib/ace/keyboard/vim/commands.js index a9b24aa3..c0936f31 100644 --- a/lib/ace/keyboard/vim/commands.js +++ b/lib/ace/keyboard/vim/commands.js @@ -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) { diff --git a/lib/ace/keyboard/vim/maps/motions.js b/lib/ace/keyboard/vim/maps/motions.js index 036930ec..c143d218 100644 --- a/lib/ace/keyboard/vim/maps/motions.js +++ b/lib/ace/keyboard/vim/maps/motions.js @@ -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; diff --git a/lib/ace/mode/css_worker.js b/lib/ace/mode/css_worker.js index 09802cad..b542bda9 100644 --- a/lib/ace/mode/css_worker.js +++ b/lib/ace/mode/css_worker.js @@ -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); diff --git a/lib/ace/worker/worker.js b/lib/ace/worker/worker.js index f3910e2a..46f173a5 100644 --- a/lib/ace/worker/worker.js +++ b/lib/ace/worker/worker.js @@ -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) {