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

[Fix] Don't add beginning newline of linewise put in visual-mode #2579

Merged
merged 2 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1289,12 +1289,12 @@ export class PutCommand extends BaseCommand {
textToAdd = text;
whereToAddText = dest;
} else if (
vimState.currentMode === ModeName.Visual &&
(vimState.currentMode === ModeName.Visual || vimState.currentMode === ModeName.VisualLine) &&
register.registerMode === RegisterMode.LineWise
) {
// in the specific case of linewise register data during visual mode,
// we need extra newline feeds
textToAdd = '\n' + text + '\n';
textToAdd = (vimState.currentMode === ModeName.Visual ? '\n' : '') + text + '\n';
whereToAddText = dest;
} else {
if (adjustIndent) {
Expand Down Expand Up @@ -1524,6 +1524,7 @@ export class PutCommandVisual extends BaseCommand {

// If the to be inserted text is linewise we have a seperate logic delete the
// selection first than insert
let oldMode = vimState.currentMode;
let register = await Register.get(vimState);
if (register.registerMode === RegisterMode.LineWise) {
let deleteResult = await new operator.DeleteOperator(this.multicursorIndex).run(
Expand All @@ -1533,11 +1534,12 @@ export class PutCommandVisual extends BaseCommand {
false
);
// to ensure, that the put command nows this is
// an linewise register insertion in visual mode
let oldMode = deleteResult.currentMode;
deleteResult.currentMode = ModeName.Visual;
deleteResult = await new PutCommand().exec(start, deleteResult, true);
// an linewise register insertion in visual mode of
// characterwise, linewise
let resultMode = deleteResult.currentMode;
deleteResult.currentMode = oldMode;
deleteResult = await new PutCommand().exec(start, deleteResult, true);
deleteResult.currentMode = resultMode;
return deleteResult;
}

Expand Down
9 changes: 9 additions & 0 deletions test/mode/modeVisualLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,13 @@ suite('Mode Visual Line', () => {
assertEqualLines(['one two threeone two three', 'one two three']);
});
});

suite('replace text in linewise visual-mode with linewise register content', () => {
newTest({
title: 'yyVp does not change the content but changes cursor position',
start: ['fo|o', 'bar', 'fun', 'baz'],
keysPressed: 'yyVp',
end: ['|foo', 'bar', 'fun', 'baz'],
});
});
});