Skip to content

Commit

Permalink
Merge pull request #3087 from JKillian/fixMultilineYank
Browse files Browse the repository at this point in the history
Multiline yank writes to 0 register; fixes #1214
  • Loading branch information
xconverge authored Oct 6, 2018
2 parents ffebf09 + 3e7adb2 commit 047362c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/register/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ export class Register {
*/
private static processNumberedRegister(content: RegisterContent, vimState: VimState): void {
// Find the BaseOperator of the current actions
const baseOperator = vimState.recordedState.actionsRun.find(value => {
return value instanceof BaseOperator || value instanceof BaseCommand;
});
const baseOperator = vimState.recordedState.operator || vimState.recordedState.command;

if (baseOperator instanceof YankOperator || baseOperator instanceof CommandYankFullLine) {
// 'yank' to 0 only if no register was specified
Expand Down
2 changes: 1 addition & 1 deletion src/state/recordedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class RecordedState {
* The command (e.g. i, ., R, /) the user wants to run, if there is one.
*/
public get command(): BaseCommand {
const list = _.filter(this.actionsRun, a => a instanceof BaseCommand);
const list = _.filter(this.actionsRun, a => a instanceof BaseCommand).reverse();

// TODO - disregard <Esc>, then assert this is of length 1.

Expand Down
43 changes: 43 additions & 0 deletions test/register/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,49 @@ suite('register', () => {
assertEqualLines(['test2', 'test2', 'test3']);
});

test("Multiline yank (`[count]yy`) stores text in Register '0'", async () => {
modeHandler.vimState.editor = vscode.window.activeTextEditor!;

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

await modeHandler.handleMultipleKeyEvents([
'<Esc>',
'g',
'g',
'2',
'y',
'y',
'd',
'd',
'"',
'0',
'P',
]);

assertEqualLines(['test1', 'test2', 'test2', 'test3']);
});

test("Multiline yank (`[count]Y`) stores text in Register '0'", async () => {
modeHandler.vimState.editor = vscode.window.activeTextEditor!;

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

await modeHandler.handleMultipleKeyEvents([
'<Esc>',
'g',
'g',
'2',
'Y',
'd',
'd',
'"',
'0',
'P',
]);

assertEqualLines(['test1', 'test2', 'test2', 'test3']);
});

test("Register '1'-'9' stores delete content", async () => {
modeHandler.vimState.editor = vscode.window.activeTextEditor!;

Expand Down

0 comments on commit 047362c

Please sign in to comment.