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 bug joining lines with whitespace only next line #799

Merged
merged 1 commit into from
Sep 26, 2016
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
6 changes: 3 additions & 3 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2934,15 +2934,15 @@ class ActionJoin extends BaseCommand {
let lineOne = TextEditor.getLineAt(position).text;
let lineTwo = TextEditor.getLineAt(position.getNextLineBegin()).text;

lineTwo = lineTwo.substring(position.getNextLineBegin().getFirstLineNonBlankChar().character);
let lineTwoTrimmedStart = lineTwo.substring(position.getNextLineBegin().getFirstLineNonBlankChar().character);

// TODO(whitespace): need a better way to check for whitespace
let oneEndsWithWhitespace = lineOne.length > 0 && " \t".indexOf(lineOne[lineOne.length - 1]) > -1;
let isParenthesisPair = (lineOne[lineOne.length - 1] === '(' && lineTwo[0] === ')');
let isParenthesisPair = (lineOne[lineOne.length - 1] === '(' && lineTwoTrimmedStart[0] === ')');

const addSpace = !oneEndsWithWhitespace && !isParenthesisPair;

let resultLine = lineOne + (addSpace ? " " : "") + lineTwo;
let resultLine = lineOne + (addSpace ? " " : "") + lineTwoTrimmedStart;

let newState = await new DeleteOperator().run(
vimState,
Expand Down
7 changes: 7 additions & 0 deletions test/mode/normalModeTests/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ suite("Mode Normal", () => {
end: ['one| two']
});

newTest({
title: "Can handle 'J' with only white space on next line",
start: ['on|e', ' '],
keysPressed: 'J',
end: ['one| ']
});

newTest({
title: "Can handle 'J' with TWO indented lines",
start: [' on|e', ' two'],
Expand Down