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 #2168: Surround offset #2171

Merged
merged 3 commits into from
Nov 22, 2017
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
4 changes: 3 additions & 1 deletion src/actions/plugins/surround.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ export class CommandSurroundAddToReplacement extends BaseCommand {
let start = vimState.surround.range.start;
let stop = vimState.surround.range.stop;

stop = stop.getRight();
if (TextEditor.getCharAt(stop) !== ' ') {
stop = stop.getRight();
}

if (vimState.surround.isVisualLine) {
startReplace = startReplace + '\n';
Expand Down
49 changes: 45 additions & 4 deletions test/plugins/surround.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,69 @@ suite('surround plugin', () => {
teardown(cleanUpWorkspace);

newTest({
title: 'ysiw) surrounds word',
title: "'ysiw)' surrounds word without space",
start: ['first li|ne test'],
keysPressed: 'ysiw)',
end: ['first (|line) test'],
});

newTest({
title: 'ysiw< surrounds word with tags',
title: "'ysiw(' surrounds word with space",
start: ['first li|ne test'],
keysPressed: 'ysiw(',
end: ['first ( |line ) test'],
});

newTest({
title: "'ysw)' surrounds word without space",
start: ['first |line test'],
keysPressed: 'ysw)',
end: ['first (|line) test'],
});

newTest({
title: "'ysw(' surrounds word with space",
start: ['first |line test'],
keysPressed: 'ysw(',
end: ['first ( |line ) test'],
});
newTest({
title: "'ysaw)' surrounds word without space",
start: ['first li|ne test'],
keysPressed: 'ysaw)',
end: ['first (|line) test'],
});

newTest({
title: "'ysaw(' surrounds word with space",
start: ['first li|ne test'],
keysPressed: 'ysaw(',
end: ['first ( |line ) test'],
});

newTest({
title: "'ysiw(' surrounds word with space and ignores punctuation",
start: ['first li|ne.test'],
keysPressed: 'ysiw(',
end: ['first ( |line ).test'],
});

newTest({
title: "'ysiw<' surrounds word with tags",
start: ['first li|ne test'],
keysPressed: 'ysiw<123>',
end: ['first <123>|line</123> test'],
});

newTest({
title: 'ysiw< surrounds word with tags and attributes',
title: "'ysiw<' surrounds word with tags and attributes",
start: ['first li|ne test'],
keysPressed: 'ysiw<abc attr1 attr2="test">',
end: ['first <abc attr1 attr2="test">|line</abc> test'],
});

newTest({
title: 'yss) surrounds entire line respecting whitespace',
title: "'yss)' surrounds entire line respecting whitespace",
start: ['foo', ' foob|ar '],
keysPressed: 'yss)',
end: ['foo', ' (|foobar) '],
Expand Down