Skip to content

Commit

Permalink
Merge pull request #2602 from tyru/v_p-should-update-register
Browse files Browse the repository at this point in the history
[Fix] p in visual-mode should update register content
  • Loading branch information
xconverge committed May 4, 2018
2 parents 9d73644 + 8da7fcc commit 54e181b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/actions/commands/actions.ts
Expand Up @@ -1547,11 +1547,18 @@ export class PutCommandVisual extends BaseCommand {
let oldMode = vimState.currentMode;
let register = await Register.get(vimState);
if (register.registerMode === RegisterMode.LineWise) {
const replaceRegister = await Register.getByKey(vimState.recordedState.registerName);
let deleteResult = await new operator.DeleteOperator(this.multicursorIndex).run(
vimState,
start,
end,
false
true
);
const deletedRegister = await Register.getByKey(vimState.recordedState.registerName);
Register.putByKey(
replaceRegister.text,
vimState.recordedState.registerName,
replaceRegister.registerMode
);
// to ensure, that the put command nows this is
// an linewise register insertion in visual mode of
Expand All @@ -1560,6 +1567,11 @@ export class PutCommandVisual extends BaseCommand {
deleteResult.currentMode = oldMode;
deleteResult = await new PutCommand().exec(start, deleteResult, true);
deleteResult.currentMode = resultMode;
Register.putByKey(
deletedRegister.text,
vimState.recordedState.registerName,
deletedRegister.registerMode
);
return deleteResult;
}

Expand Down
9 changes: 9 additions & 0 deletions test/mode/modeVisualLine.test.ts
Expand Up @@ -316,6 +316,15 @@ suite('Mode Visual Line', () => {
});
});

newTest({
title: 'Vp updates register content',
start: ['|hello', 'world'],
keysPressed: 'ddVpP',
// TODO: this is not the same behavior as original Vim.
// But currently unnecessary line is left at the end (see #2602).
end: ['|world', 'hello', ''],
});

suite('replace text in linewise visual-mode with linewise register content', () => {
newTest({
title: 'yyVp does not change the content but changes cursor position',
Expand Down

0 comments on commit 54e181b

Please sign in to comment.