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 #1554, #1553: Fixed daW bugs #1555

Merged
merged 5 commits into from
Apr 24, 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
21 changes: 16 additions & 5 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5287,14 +5287,17 @@ class SelectWord extends TextObjectMovement {
public async execAction(position: Position, vimState: VimState): Promise<IMovement> {
let start: Position;
let stop: Position;

const currentChar = TextEditor.getLineAt(position).text[position.character];

if (/\s/.test(currentChar)) {
start = position.getLastWordEnd().getRight();
stop = position.getCurrentWordEnd();
} else {
stop = position.getWordRight();
// If the next word is not at the beginning of the next line, we want to pretend it is.
// This is because 'aw' has two fundamentally different behaviors distinguished by whether
// the next word is directly after the current word, as described in the following comment.
// The only case that's not true is in cases like #1350.
if (stop.isEqual(stop.getFirstLineNonBlankChar())) {
stop = stop.getLineBegin();
}
Expand All @@ -5303,7 +5306,8 @@ class SelectWord extends TextObjectMovement {
// then we delete the spaces to the left of the current word. Otherwise, we delete to the right.
// 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())) {
!position.getWordLeft(true).isEqual(position.getFirstLineNonBlankChar())
&& vimState.recordedState.count === 0) {
start = position.getLastWordEnd().getRight();
} else {
start = position.getWordLeft(true);
Expand Down Expand Up @@ -5344,10 +5348,17 @@ class SelectABigWord extends TextObjectMovement {
start = position.getLastBigWordEnd().getRight();
stop = position.getCurrentBigWordEnd();
} else {
start = position.getBigWordLeft();
stop = position.getBigWordRight().getLeft();
// Check 'aw' code for much of the reasoning behind this logic.
let nextWord = position.getBigWordRight();
if ((nextWord.isEqual(nextWord.getFirstLineNonBlankChar()) || nextWord.isLineEnd()) &&
vimState.recordedState.count === 0) {
start = position.getLastWordEnd().getRight();
stop = position.getLineEnd();
} else {
start = position.getBigWordLeft(true);
stop = position.getBigWordRight().getLeft();
}
}

if (vimState.currentMode === ModeName.Visual && !vimState.cursorPosition.isEqual(vimState.cursorStartPosition)) {
start = vimState.cursorStartPosition;

Expand Down
6 changes: 3 additions & 3 deletions src/motion/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ export class Position extends vscode.Position {
return this.getWordLeftWithRegex(this._nonWordCharRegex, inclusive);
}

public getBigWordLeft(): Position {
return this.getWordLeftWithRegex(this._nonBigWordCharRegex);
public getBigWordLeft(inclusive: boolean = false): Position {
return this.getWordLeftWithRegex(this._nonBigWordCharRegex, inclusive);
}

public getFilePathLeft(inclusive: boolean = false): Position {
Expand All @@ -495,7 +495,7 @@ export class Position extends vscode.Position {
return this.getWordRightWithRegex(this._nonWordCharRegex, inclusive);
}

public getBigWordRight() : Position {
public getBigWordRight(inclusive: boolean = false) : Position {
return this.getWordRightWithRegex(this._nonBigWordCharRegex);
}

Expand Down
32 changes: 32 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,14 @@ suite("Mode Normal", () => {
endMode: ModeName.Normal
});

newTest({
title: "Can handle 'daw' on word with numeric prefix and across lines",
start: ['one two fo|ur', 'five six'],
keysPressed: 'd2aw',
end: ['one two |six'],
endMode: ModeName.Normal
});

newTest({
title: "Can handle 'daw' on word with numeric prefix and across lines, containing words end with `.`",
start: ['one two three, fo|ur ', 'five. six'],
Expand Down Expand Up @@ -734,6 +742,30 @@ suite("Mode Normal", () => {
endMode: ModeName.Normal
});

newTest({
title: "Can handle 'daW' on beginning of word",
start: ['one |two three'],
keysPressed: 'daW',
end: ['one |three'],
endMode: ModeName.Normal
});

newTest({
title: "Can handle 'daW' on end of one line",
start: ['one |two'],
keysPressed: 'daW',
end: ['on|e'],
endMode: ModeName.Normal
});
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 'diw' on word with cursor inside spaces",
start: ['one two | three, four '],
Expand Down