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

Fixes #1193, #1350, #967: Fixes daw bugs #1549

Merged
merged 10 commits into from
Apr 23, 2017
10 changes: 8 additions & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5294,10 +5294,16 @@ class SelectWord extends TextObjectMovement {
start = position.getLastWordEnd().getRight();
stop = position.getCurrentWordEnd();
} else {
stop = position.getWordRight().getLeftThroughLineBreaks();
stop = position.getWordRight();
if (stop.isEqual(stop.getFirstLineNonBlankChar())) {
stop = stop.getLineBegin();
}
stop = stop.getLeftThroughLineBreaks().getLeftIfEOL();
// If we aren't separated from the next word by whitespace(like in "horse ca|t,dog" or at the end of the line)
// then we delete the spaces to the left of the current word. Otherwise, we delete to the right.
if (stop.isEqual(position.getCurrentWordEnd(true))) {
// Also, if the current word is the leftmost word, we only delete from the start of the word to the end.
if (stop.isEqual(position.getCurrentWordEnd(true)) &&
!position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())) {
start = position.getLastWordEnd().getRight();
} else {
start = position.getWordLeft(true);
Expand Down
53 changes: 51 additions & 2 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,57 @@ suite("Mode Normal", () => {
endMode: ModeName.Normal
});

newTest({
title: "Can handle 'daw' on words at beginning of line with leading whitespace",
start: ['if (something){',
' |this.method();'],
keysPressed: 'daw',
end: ['if (something){',
' |.method();']
});

newTest({
title: "Can handle 'daw' on words at ends of lines in the middle of whitespace",
start: ['one two | ',
'four'],
keysPressed: 'daw',
end: ['one tw|o']
});

newTest({
title: "Can handle 'daw' on word at beginning of file",
start: ['o|ne'],
keysPressed: 'daw',
end: ['|']
});

newTest({
title: "Can handle 'daw' on word at beginning of line",
start: ['one two',
'th|ree'],
keysPressed: 'daw',
end: ['one two',
'|']
});

newTest({
title: "Can handle 'daw' on word at end of line with trailing whitespace",
start: ['one tw|o ',
'three four'],
keysPressed: 'daw',
end: ['one| ',
'three four']
});

newTest({
title: "Can handle 'daw' around word at end of line",
start: ['one t|wo',
' three'],
keysPressed: 'daw',
end: ['on|e',
' three']
});

newTest({
title: "Can handle 'daW' on big word with cursor inside spaces",
start: ['one two | three, four '],
Expand Down Expand Up @@ -683,8 +734,6 @@ suite("Mode Normal", () => {
endMode: ModeName.Normal
});



newTest({
title: "Can handle 'diw' on word with cursor inside spaces",
start: ['one two | three, four '],
Expand Down