Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add small deletions to small delete register #3544

Merged
merged 8 commits into from
Mar 9, 2019
Merged
4 changes: 2 additions & 2 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3132,7 +3132,7 @@ export class ActionDeleteChar extends BaseCommand {
}

@RegisterAction
class ActionDeleteCharWithDeleteKey extends BaseCommand {
export class ActionDeleteCharWithDeleteKey extends BaseCommand {
modes = [ModeName.Normal];
keys = ['<Del>'];
runsOnceForEachCountPrefix = true;
Expand All @@ -3154,7 +3154,7 @@ class ActionDeleteCharWithDeleteKey extends BaseCommand {
}

@RegisterAction
class ActionDeleteLastChar extends BaseCommand {
export class ActionDeleteLastChar extends BaseCommand {
modes = [ModeName.Normal];
keys = ['X'];
canBeRepeatedWithDot = true;
Expand Down
7 changes: 6 additions & 1 deletion src/register/register.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Clipboard } from './../util/clipboard';
import {
ActionDeleteChar,
ActionDeleteCharWithDeleteKey,
ActionDeleteLastChar,
CommandRegister,
CommandYankFullLine,
} from './../actions/commands/actions';
Expand Down Expand Up @@ -320,7 +322,10 @@ export class Register {
Register.registers['0'].registerMode = vimState.effectiveRegisterMode;
}
} else if (
(baseOperator instanceof DeleteOperator || baseOperator instanceof ActionDeleteChar) &&
(baseOperator instanceof DeleteOperator ||
baseOperator instanceof ActionDeleteChar ||
baseOperator instanceof ActionDeleteLastChar ||
baseOperator instanceof ActionDeleteCharWithDeleteKey) &&
!(vimState.isRecordingMacro || vimState.isReplayingMacro)
) {
if (
Expand Down
45 changes: 43 additions & 2 deletions test/register/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,54 @@ suite('register', () => {
}
});

test('Small deleteion is stored in small delete register', async () => {
test('Small deleteion using x is stored in small delete register', async () => {
rickythefox marked this conversation as resolved.
Show resolved Hide resolved
modeHandler.vimState.editor = vscode.window.activeTextEditor!;

modeHandler.vimState.registerName = '-';
Register.put('', modeHandler.vimState);

await modeHandler.handleMultipleKeyEvents('itest1\ntest2\ntest3'.split(''));

await modeHandler.handleMultipleKeyEvents(['<Esc>', 'g', 'g', '2', 'x', 'j', '"', '-', 'p']);

assertEqualLines(['st1', 'tteest2', 'test3']);
});
});

test('Small deleteion using x is stored in small delete register', async () => {
rickythefox marked this conversation as resolved.
Show resolved Hide resolved
modeHandler.vimState.editor = vscode.window.activeTextEditor!;

modeHandler.vimState.registerName = '-';
Register.put('', modeHandler.vimState);

await modeHandler.handleMultipleKeyEvents('itest1\ntest2\ntest3'.split(''));

await modeHandler.handleMultipleKeyEvents(['<Esc>', 'g', 'g', '<Del>', 'j', '"', '-', 'p']);

assertEqualLines(['est1', 'ttest2', 'test3']);
});

test('Small deleteion using X is stored in small delete register', async () => {
modeHandler.vimState.editor = vscode.window.activeTextEditor!;

modeHandler.vimState.registerName = '-';
Register.put('', modeHandler.vimState);

await modeHandler.handleMultipleKeyEvents('itest1\ntest2\ntest3'.split(''));

await modeHandler.handleMultipleKeyEvents([
'<Esc>',
'g',
'g',
'l',
'l',
'2',
'X',
'j',
'"',
'-',
'p',
]);

assertEqualLines(['st1', 'tteest2', 'test3']);
});
});