From 59f5e7ffca7d37b6b808772a9a7d438ac1d6f003 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 29 Nov 2012 23:19:16 +0400 Subject: [PATCH 1/5] [vim] pass unhandled keys to the browser --- lib/ace/keyboard/keybinding.js | 34 +++++++++++++++----------------- lib/ace/keyboard/vim.js | 4 +++- lib/ace/keyboard/vim/commands.js | 5 ++++- 3 files changed, 23 insertions(+), 20 deletions(-) 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..a4f1c39d 100644 --- a/lib/ace/keyboard/vim.js +++ b/lib/ace/keyboard/vim.js @@ -101,7 +101,9 @@ exports.handler = { 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..7cb15c2c 100644 --- a/lib/ace/keyboard/vim/commands.js +++ b/lib/ace/keyboard/vim/commands.js @@ -305,6 +305,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 +370,7 @@ var inputBuffer = exports.inputBuffer = { this.exec(editor, { operator: this.operator }, ch); } else { + isKeyHandled = ch.length == 1; this.reset(); } @@ -379,9 +381,10 @@ var inputBuffer = exports.inputBuffer = { } else if (this.status) { this.status = ""; } else { - return; + return isKeyHandled; } editor._emit("changeStatus"); + return isKeyHandled; }, waitForParam: function(cmd) { From 989f318d878c67a442103a8161c60885cc9cef3a Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 30 Nov 2012 22:25:01 +0400 Subject: [PATCH 2/5] [vim] add ctrl+x ctrl+a --- lib/ace/keyboard/vim/commands.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ace/keyboard/vim/commands.js b/lib/ace/keyboard/vim/commands.js index 7cb15c2c..c0889a12 100644 --- a/lib/ace/keyboard/vim/commands.js +++ b/lib/ace/keyboard/vim/commands.js @@ -288,7 +288,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 = { From 92e4a42f8957bd9afcd94f7294d0fe370c289eec Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 30 Nov 2012 22:26:00 +0400 Subject: [PATCH 3/5] [vim] fix left/right motions --- lib/ace/keyboard/vim.js | 2 +- lib/ace/keyboard/vim/maps/motions.js | 7 +++++-- lib/ace/mode/css_worker.js | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ace/keyboard/vim.js b/lib/ace/keyboard/vim.js index a4f1c39d..7e8ec739 100644 --- a/lib/ace/keyboard/vim.js +++ b/lib/ace/keyboard/vim.js @@ -96,7 +96,7 @@ 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 { diff --git a/lib/ace/keyboard/vim/maps/motions.js b/lib/ace/keyboard/vim/maps/motions.js index 036930ec..37200183 100644 --- a/lib/ace/keyboard/vim/maps/motions.js +++ b/lib/ace/keyboard/vim/maps/motions.js @@ -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(); @@ -575,7 +579,6 @@ 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); 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); From 91788f342480b7e406908a860f11b96bb1ab265e Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 15 Dec 2012 17:37:15 +0400 Subject: [PATCH 4/5] #1151 initial support for marks --- lib/ace/keyboard/vim/commands.js | 12 +++++++++ lib/ace/keyboard/vim/maps/motions.js | 37 ++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/lib/ace/keyboard/vim/commands.js b/lib/ace/keyboard/vim/commands.js index c0889a12..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(); diff --git a/lib/ace/keyboard/vim/maps/motions.js b/lib/ace/keyboard/vim/maps/motions.js index 37200183..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 @@ -386,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; } } @@ -563,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": { @@ -583,7 +583,34 @@ module.exports = { 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; From fdab3cd059f4f83704e78798f0afe4294abf905f Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 15 Dec 2012 17:38:27 +0400 Subject: [PATCH 5/5] get rid of annoying mesages in firebug --- lib/ace/worker/worker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) {