From 2eabebccaaf767e249c8370cbfbef3b73c8335bc Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 1 Mar 2013 14:37:09 +0400 Subject: [PATCH] fix r+enter, add ,; --- lib/ace/keyboard/vim/commands.js | 20 +++++------- lib/ace/keyboard/vim/maps/motions.js | 49 +++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/lib/ace/keyboard/vim/commands.js b/lib/ace/keyboard/vim/commands.js index 3b9f1d1d..bc698e46 100644 --- a/lib/ace/keyboard/vim/commands.js +++ b/lib/ace/keyboard/vim/commands.js @@ -90,6 +90,8 @@ var actions = exports.actions = { param: true, fn: function(editor, range, count, param) { if (param && param.length) { + if (param.length > 1) + param = param == "return" ? "\n" : param == "tab" ? "\t" : param; repeat(function() { editor.insert(param); }, count || 1); editor.navigateLeft(); } @@ -286,26 +288,20 @@ var actions = exports.actions = { var val = ":"; if (count > 1) val = ".,.+" + count + val; - if (editor.cmdLine) { - editor.cmdLine.setValue(val, 1); - editor.cmdLine.focus(); - } + if (editor.showCommandLine) + editor.showCommandLine(val); } }, "/": { fn: function(editor, range, count, param) { - if (editor.cmdLine) { - editor.cmdLine.setValue("/", 1); - editor.cmdLine.focus(); - } + if (editor.showCommandLine) + editor.showCommandLine("/"); } }, "?": { fn: function(editor, range, count, param) { - if (editor.cmdLine) { - editor.cmdLine.setValue("?", 1); - editor.cmdLine.focus(); - } + if (editor.showCommandLine) + editor.showCommandLine("?"); } }, ".": { diff --git a/lib/ace/keyboard/vim/maps/motions.js b/lib/ace/keyboard/vim/maps/motions.js index 961083a5..3611386b 100644 --- a/lib/ace/keyboard/vim/maps/motions.js +++ b/lib/ace/keyboard/vim/maps/motions.js @@ -138,6 +138,8 @@ function find(editor, needle, dir) { var Range = require("../../../range").Range; +var LAST_SEARCH_MOTION = {}; + module.exports = { "w": new Motion(function(editor) { var str = new StringStream(editor); @@ -381,7 +383,9 @@ module.exports = { "f": new Motion({ param: true, handlesCount: true, - getPos: function(editor, range, count, param, isSel) { + getPos: function(editor, range, count, param, isSel, isRepeat) { + if (!isRepeat) + LAST_SEARCH_MOTION = {ch: "f", param: param}; var cursor = editor.getCursorPosition(); var column = util.getRightNthChar(editor, cursor, param, count || 1); @@ -394,7 +398,9 @@ module.exports = { "F": new Motion({ param: true, handlesCount: true, - getPos: function(editor, range, count, param, isSel) { + getPos: function(editor, range, count, param, isSel, isRepeat) { + if (!isRepeat) + LAST_SEARCH_MOTION = {ch: "F", param: param}; var cursor = editor.getCursorPosition(); var column = util.getLeftNthChar(editor, cursor, param, count || 1); @@ -407,10 +413,15 @@ module.exports = { "t": new Motion({ param: true, handlesCount: true, - getPos: function(editor, range, count, param, isSel) { + getPos: function(editor, range, count, param, isSel, isRepeat) { + if (!isRepeat) + LAST_SEARCH_MOTION = {ch: "t", param: param}; var cursor = editor.getCursorPosition(); var column = util.getRightNthChar(editor, cursor, param, count || 1); + if (isRepeat && column == 0 && !(count > 1)) + var column = util.getRightNthChar(editor, cursor, param, 2); + if (typeof column === "number") { cursor.column += column + (isSel ? 1 : 0); return cursor; @@ -420,16 +431,46 @@ module.exports = { "T": new Motion({ param: true, handlesCount: true, - getPos: function(editor, range, count, param, isSel) { + getPos: function(editor, range, count, param, isSel, isRepeat) { + if (!isRepeat) + LAST_SEARCH_MOTION = {ch: "T", param: param}; var cursor = editor.getCursorPosition(); var column = util.getLeftNthChar(editor, cursor, param, count || 1); + if (isRepeat && column == 0 && !(count > 1)) + var column = util.getLeftNthChar(editor, cursor, param, 2); + if (typeof column === "number") { cursor.column -= column; return cursor; } } }), + ";": new Motion({ + handlesCount: true, + getPos: function(editor, range, count, param, isSel) { + var ch = LAST_SEARCH_MOTION.ch; + if (!ch) + return; + return module.exports[ch].getPos( + editor, range, count, LAST_SEARCH_MOTION.param, isSel, true + ); + } + }), + ",": new Motion({ + handlesCount: true, + getPos: function(editor, range, count, param, isSel) { + var ch = LAST_SEARCH_MOTION.ch; + if (!ch) + return; + var up = ch.toUpperCase(); + ch = ch === up ? ch.toLowerCase() : up; + + return module.exports[ch].getPos( + editor, range, count, LAST_SEARCH_MOTION.param, isSel, true + ); + } + }), "^": { nav: function(editor) {