From 91788f342480b7e406908a860f11b96bb1ab265e Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 15 Dec 2012 17:37:15 +0400 Subject: [PATCH] #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;