Merge pull request #1644 from Chillee/1256

Fixes #1256 and #394: Fixes delete key and adds functionality
This commit is contained in:
Sean Kelly 2017-05-09 19:54:56 -07:00 committed by GitHub
commit e38c4f67e8
4 changed files with 23 additions and 24 deletions

View File

@ -117,7 +117,7 @@
{
"key": "Delete",
"command": "extension.vim_delete",
"when": "editorTextFocus && vim.active && vim.mode == 'Normal' && !inDebugRepl"
"when": "editorTextFocus && vim.active && !inDebugRepl"
},
{
"key": "tab",

View File

@ -2240,17 +2240,18 @@ class ActionDeleteCharWithDeleteKey extends BaseCommand {
runsOnceForEachCountPrefix = true;
canBeRepeatedWithDot = true;
public async exec(position: Position, vimState: VimState): Promise<VimState> {
// N<del> is a no-op in Vim
if (vimState.recordedState.count !== 0) {
return vimState;
}
const state = await new operator.DeleteOperator(this.multicursorIndex).run(vimState, position, position);
state.currentMode = ModeName.Normal;
return state;
public async execCount(position: Position, vimState: VimState): Promise<VimState> {
// If <del> has a count in front of it, then <del> deletes a character
// off the count. Therefore, 100<del>x, would apply 'x' 10 times.
// http://vimdoc.sourceforge.net/htmldoc/change.html#<Del>
if (vimState.recordedState.count !== 0) {
vimState.recordedState.count = Math.floor(vimState.recordedState.count / 10);
vimState.recordedState.actionKeys = vimState.recordedState.count.toString().split("");
vimState.recordedState.commandList = vimState.recordedState.count.toString().split("");
this.isCompleteAction = false;
return vimState;
}
return await new ActionDeleteChar().execCount(position, vimState);
}
}

View File

@ -138,15 +138,12 @@ export class DeleteOperator extends BaseOperator {
}
public async run(vimState: VimState, start: Position, end: Position, yank = true): Promise<VimState> {
await this.delete(start, end, vimState.currentMode, vimState.effectiveRegisterMode(), vimState, yank);
let newPos = await this.delete(start, end, vimState.currentMode, vimState.effectiveRegisterMode(), vimState, yank);
vimState.currentMode = ModeName.Normal;
/*
vimState.cursorPosition = result;
vimState.cursorStartPosition = result;
*/
if (vimState.currentMode === ModeName.Visual) {
vimState.desiredColumn = newPos.character;
}
return vimState;
}
}
@ -232,12 +229,13 @@ export class ShiftYankOperatorVisual extends BaseOperator {
vimState.currentRegisterMode = RegisterMode.LineWise;
return await new YankOperator().run(vimState, start, end);
}
}
@RegisterAction
export class DeleteOperatorXVisual extends BaseOperator {
public keys = ["x"];
public keys = ["x", "<Del>"];
public modes = [ModeName.Visual, ModeName.VisualLine];
public async run(vimState: VimState, start: Position, end: Position): Promise<VimState> {

View File

@ -62,10 +62,10 @@ suite("Mode Normal", () => {
});
newTest({
title: "Can handle 'N<Del>', which should be a no-op",
start: ['te|xt'],
keysPressed: '2<Del>',
end: ["te|xt"],
title: "Can handle '<Del>' with counts, which removes the last character of the count",
start: ['|text'],
keysPressed: '10<Del>x',
end: ["|ext"],
});
newTest({