Skip to content

Commit

Permalink
Merge pull request #1621 from Chillee/1196
Browse files Browse the repository at this point in the history
Fixes #1196, #1197: d}/y} not working correctly
  • Loading branch information
xconverge authored May 10, 2017
2 parents e38c4f6 + a2a6940 commit 09b50ab
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
18 changes: 12 additions & 6 deletions src/actions/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export abstract class BaseMovement extends BaseAction {
} else {
position = temporaryResult.stop.getRightThroughLineBreaks();
}

result.registerMode = temporaryResult.registerMode;
}
}

Expand Down Expand Up @@ -1000,8 +1002,14 @@ class MoveNextSentenceBegin extends BaseMovement {
class MoveParagraphEnd extends BaseMovement {
keys = ["}"];

public async execAction(position: Position, vimState: VimState): Promise<Position> {
return position.getCurrentParagraphEnd();
public async execAction(position: Position, vimState: VimState): Promise<IMovement> {
const isLineWise = position.isLineBeginning() && vimState.currentMode === ModeName.Normal && vimState.recordedState.operator;
let paragraphEnd = position.getCurrentParagraphEnd();
return {
start: position,
stop: (isLineWise ? paragraphEnd.getLeftThroughLineBreaks(true) : paragraphEnd),
registerMode: isLineWise ? RegisterMode.LineWise : RegisterMode.FigureItOutFromCurrentMode
};
}
}

Expand Down Expand Up @@ -1302,10 +1310,8 @@ export abstract class MoveInsideCharacter extends BaseMovement {

// If the closing character is the first on the line, don't swallow it.
if (!this.includeSurrounding) {
if (endPos.character === 0 && vimState.currentMode !== ModeName.Visual) {
endPos = endPos.getLeftThroughLineBreaks();
} else if (endPos.getLeft().isInLeadingWhitespace()) {
endPos = endPos.getPreviousLineBegin().getLineEnd();
if (endPos.getLeft().isInLeadingWhitespace()) {
endPos = endPos.getLineBegin();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/actions/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export class ChangeOperator extends BaseOperator {
state.currentMode = ModeName.Insert;

if (isEndOfLine) {
state.cursorPosition = state.cursorPosition.getRight();
state.cursorPosition = state.getRight();
}

return state;
Expand Down
13 changes: 11 additions & 2 deletions src/actions/textobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,23 @@ abstract class IndentObjectMatch extends TextObjectMovement {
// TextEditor.getLineMaxColumn throws when given line 0, which we don't
// care about here since it just means this text object wouldn't work on a
// single-line document.
const endCharacter = TextEditor.readLineAt(endLineNumber).length;

let endCharacter;
if (endLineNumber === TextEditor.getLineCount() - 1 || vimState.currentMode === ModeName.Visual) {
endCharacter = TextEditor.getLineMaxColumn(endLineNumber);
} else {
endCharacter = 0;
endLineNumber++;
}
return {
start: new Position(startLineNumber, startCharacter),
stop: new Position(endLineNumber, endCharacter),
};
}

public async execActionForOperator(position: Position, vimState: VimState): Promise<IMovement> {
return await this.execAction(position, vimState);
}

/**
* Searches up from the cursor for the first non-empty line.
*/
Expand Down
19 changes: 3 additions & 16 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,16 +1211,7 @@ export class ModeHandler implements vscode.Disposable {
vimState.recordedState.count = 0;

// Keep the cursor within bounds

if (vimState.currentMode === ModeName.Normal && !recordedState.operator) {
for (const { stop, i } of Range.IterateRanges(vimState.allCursors)) {
if (stop.character >= Position.getLineLength(stop.line)) {
vimState.allCursors[i].withNewStop(
stop.getLineEnd().getLeft()
);
}
}
} else {
if (vimState.currentMode !== ModeName.Normal || recordedState.operator) {
let stop = vimState.cursorPosition;

// Vim does this weird thing where it allows you to select and delete
Expand Down Expand Up @@ -1260,12 +1251,8 @@ export class ModeHandler implements vscode.Disposable {
}

if (!cachedMode.isVisualMode && cachedRegister !== RegisterMode.LineWise) {
if (Position.EarlierOf(start, stop) === start) {
stop = stop.getLeft();
} else {
stop = stop.getRight();
}
}
stop = stop.getLeftThroughLineBreaks(true);
}

if (this.currentModeName === ModeName.VisualLine) {
start = start.getLineBegin();
Expand Down
21 changes: 18 additions & 3 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,22 @@ suite("Mode Normal", () => {
endMode: ModeName.Normal
});

newTest({
title: "Can handle d}",
start: ['|foo', 'bar', '', 'fun'],
keysPressed: 'd}',
end: ['|', 'fun'],
endMode: ModeName.Normal
});

newTest({
title: "Can handle y} at beginning of line",
start: ['|foo', 'bar', '', 'fun'],
keysPressed: 'y}p',
end: ['foo', '|foo', 'bar', 'bar', '', 'fun'],
endMode: ModeName.Normal
});

newTest({
title: "Select sentence with trailing spaces",
start: ["That's my sec|ret, Captain. I'm always angry."],
Expand Down Expand Up @@ -1658,8 +1674,7 @@ Disabling test until upstream VSCode issue is resolved: https://github.com/Micro
],
keysPressed: "dai",
end: [
'|',
'do_something_else()',
'|do_something_else()',
],
endMode: ModeName.Normal
});
Expand Down Expand Up @@ -1695,4 +1710,4 @@ Disabling test until upstream VSCode issue is resolved: https://github.com/Micro
],
endMode: ModeName.Normal
});
});
});

0 comments on commit 09b50ab

Please sign in to comment.