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 replace character (r) behavior with newline #3735

Merged
merged 1 commit into from
May 7, 2019
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
10 changes: 10 additions & 0 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,16 @@ class ActionReplaceCharacter extends BaseCommand {
cursorIndex: this.multicursorIndex,
diff: new PositionDiff(0, -1),
});
} else if (toReplace === '\n') {
// A newline replacement always inserts exactly one newline (regardless
// of count prefix) and puts the cursor on the next line.
vimState.recordedState.transformations.push({
type: 'replaceText',
text: '\n',
start: position,
end: endPos,
diff: PositionDiff.NewBOLDiff(1),
});
} else {
vimState.recordedState.transformations.push({
type: 'replaceText',
Expand Down
15 changes: 15 additions & 0 deletions test/mode/normalModeTests/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ suite('Mode Normal', () => {
end: ['one', '|Three'],
});

newTest({
title: "Can handle 'r\n'",
start: ['abc|defg', '12345'],
keysPressed: 'r\n',
end: ['abc', '|efg', '12345'],
});

// `r` only ever inserts one newline, regardless of count prefix
newTest({
title: "Can handle '<Count>r\n'",
start: ['abc|defg', '12345'],
keysPressed: '3r\n',
end: ['abc', '|g', '12345'],
});

newTest({
title: "Can handle 'J' once",
start: ['one', 'tw|o'],
Expand Down