Skip to content

Commit

Permalink
[Bug 419932] [Editor] Vi Keybindings - 'r' places cursor correctly an…
Browse files Browse the repository at this point in the history
…d uses a compound change on undo stack --Signed-off-by: Steve Jahns <s.t.jahns@gmail.com>
  • Loading branch information
stjahns committed Nov 13, 2013
1 parent 6f495b1 commit 9eb85d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions bundles/org.eclipse.orion.client.editor/web/orion/editor/vi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ define("orion/editor/vi", [ //$NON-NLS-0$
}


function NumberMode(textView, key, msg){
function NumberMode(textView, undoStack, key, msg){
this.undoStack = undoStack;
this.key = key;
this.msg = msg;
this.number = "";
Expand Down Expand Up @@ -381,6 +382,16 @@ define("orion/editor/vi", [ //$NON-NLS-0$
//TODO: this works if gotoLine is registered (not part of textview) - need to handle fail case
}, this._msg("viG")); //$NON-NLS-0$
},
startUndo: function() {
if (this.undoStack) {
this.undoStack.startCompoundChange();
}
},
endUndo: function() {
if (this.undoStack) {
this.undoStack.endCompoundChange();
}
},
_invoke: function(action, data) {
var view = this.getView();
data = data || {};
Expand Down Expand Up @@ -501,10 +512,10 @@ define("orion/editor/vi", [ //$NON-NLS-0$


//Edit Mode
function EditMode(viMode, nextMode, key, msg) {
function EditMode(viMode, nextMode, undoStack, key, msg) {
this.viMode = viMode;
this.nextMode = nextMode;
NumberMode.call(this, viMode.getView(), key, msg);
NumberMode.call(this, viMode.getView(), undoStack, key, msg);
}

EditMode.prototype = new NumberMode();
Expand Down Expand Up @@ -661,12 +672,12 @@ define("orion/editor/vi", [ //$NON-NLS-0$
}
});

function VIMode(textView, statusReporter){
NumberMode.call(this, textView, "", messages.vimove);
function VIMode(textView, undoStack, statusReporter){
NumberMode.call(this, textView, undoStack, "", messages.vimove);
this.insertMode = new InsertMode(this);
this.changeMode = new EditMode(this, this.insertMode, "c", messages.vichange); //$NON-NLS-0$
this.deleteMode = new EditMode(this, this, "d", messages.videlete); //$NON-NLS-0$
this.yankMode = new EditMode(this, this, "y", messages.viyank); //$NON-NLS-0$
this.changeMode = new EditMode(this, this.insertMode, undoStack, "c", messages.vichange); //$NON-NLS-0$
this.deleteMode = new EditMode(this, this, undoStack, "d", messages.videlete); //$NON-NLS-0$
this.yankMode = new EditMode(this, this, undoStack, "y", messages.viyank); //$NON-NLS-0$
this.getCharMode = new GetCharMode(this, textView);
this.statusReporter = statusReporter;
}
Expand Down Expand Up @@ -817,12 +828,14 @@ define("orion/editor/vi", [ //$NON-NLS-0$
var num = self._getCount();
self.getCharMode.callback = function(char) {
// Replace character under cursor (or next 'num' chars) with char
self.startUndo();
var caretOffset = view.getCaretOffset();
var nextCharOffset = view.getNextOffset(caretOffset, {unit:"character", count: num}); //$NON-NLS-0$
var replaceString = new Array(num+1).join(char);
view.setText(replaceString, caretOffset, nextCharOffset);
view.setSelection(caretOffset, caretOffset);
};
view.setSelection(caretOffset + num - 1, caretOffset + num - 1);
self.endUndo();
};
view.addKeyMode(self.getCharMode);
self.number = "";
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ define([
textView.addKeyMode(this.emacs);
} else if (prefs.keyBindings === "vi") { //$NON-NLS-0$
if (!this.vi) {
this.vi = new mVI.VIMode(textView, this.statusReporter.bind(this));
this.vi = new mVI.VIMode(textView, this.editor.getUndoStack(), this.statusReporter.bind(this));
}
textView.addKeyMode(this.vi);
}
Expand Down

0 comments on commit 9eb85d0

Please sign in to comment.