Skip to content

Commit

Permalink
[vim] fix insert mode repeat after delete
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed May 12, 2016
1 parent edd676b commit 74aa98c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
32 changes: 19 additions & 13 deletions lib/ace/keyboard/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,15 @@ define(function(require, exports, module) {
return this.ace.inVirtualSelectionMode && this.ace.selection.index;
};
this.onChange = function(delta) {
if (delta.action[0] == 'i') {
var change = { text: delta.lines };
var curOp = this.curOp = this.curOp || {};
if (!curOp.changeHandlers)
curOp.changeHandlers = this._eventRegistry["change"] && this._eventRegistry["change"].slice();
if (this.virtualSelectionMode()) return;
if (!curOp.lastChange) {
curOp.lastChange = curOp.change = change;
} else {
curOp.lastChange.next = curOp.lastChange = change;
}
var change = { text: delta.action[0] == 'i' ? delta.lines : [] };
var curOp = this.curOp = this.curOp || {};
if (!curOp.changeHandlers)
curOp.changeHandlers = this._eventRegistry["change"] && this._eventRegistry["change"].slice();
if (this.virtualSelectionMode()) return;
if (!curOp.lastChange) {
curOp.lastChange = curOp.change = change;
} else {
curOp.lastChange.next = curOp.lastChange = change;
}
this.$updateMarkers(delta);
};
Expand Down Expand Up @@ -5001,7 +4999,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
}
}
}
throw Error('No such mapping.');
// throw Error('No such mapping.');
}
};

Expand Down Expand Up @@ -5699,6 +5697,10 @@ dom.importCssString(".normal-mode .ace_cursor{\
if (changeObj.origin == '+input' || changeObj.origin == 'paste'
|| changeObj.origin === undefined /* only in testing */) {
var text = changeObj.text.join('\n');
if (lastChange.maybeReset) {
lastChange.changes = [];
lastChange.maybeReset = false;
}
lastChange.changes.push(text);
}
// Change objects may be chained with next.
Expand All @@ -5721,7 +5723,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
lastChange.expectCursorActivityForChange = false;
} else {
// Cursor moved outside the context of an edit. Reset the change.
lastChange.changes = [];
lastChange.maybeReset = true;
}
} else if (!cm.curOp.isVimOp) {
handleExternalSelection(cm, vim);
Expand Down Expand Up @@ -5785,6 +5787,10 @@ dom.importCssString(".normal-mode .ace_cursor{\
var keyName = CodeMirror.keyName(e);
if (!keyName) { return; }
function onKeyFound() {
if (lastChange.maybeReset) {
lastChange.changes = [];
lastChange.maybeReset = false;
}
lastChange.changes.push(new InsertModeKey(keyName));
return true;
}
Expand Down
10 changes: 9 additions & 1 deletion lib/ace/keyboard/vim_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function testVim(name, run, opts, expectedFail) {
// Record for insert mode.
if (handled == "handled" && cm.state.vim.insertMode && arguments[i] != 'Esc') {
var lastChange = CodeMirror.Vim.getVimGlobalState_().macroModeState.lastInsertModeChanges;
if (lastChange) {
if (lastChange && (key.indexOf('Delete') != -1 || key.indexOf('Backspace') != -1)) {
lastChange.changes.push(new CodeMirror.Vim.InsertModeKey(key));
}
}
Expand Down Expand Up @@ -2905,6 +2905,14 @@ testVim('._insert', function(cm, vim, helpers) {
helpers.doKeys('.');
eq('testestt', cm.getValue());
helpers.assertCursorAt(0, 6);
helpers.doKeys('O');
cm.replaceRange('xyz', cm.getCursor());
helpers.doInsertModeKeys('Backspace');
helpers.doInsertModeKeys('Down');
helpers.doKeys('<Esc>');
helpers.doKeys('.');
eq('xy\nxy\ntestestt', cm.getValue());
helpers.assertCursorAt(1, 1);
}, { value: ''});
testVim('._insert_repeat', function(cm, vim, helpers) {
helpers.doKeys('i');
Expand Down

0 comments on commit 74aa98c

Please sign in to comment.