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 c on line beginning#1302 #1303

Merged
merged 5 commits into from
Feb 15, 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
5 changes: 4 additions & 1 deletion src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2084,13 +2084,16 @@ export class ChangeOperator extends BaseOperator {

public async run(vimState: VimState, start: Position, end: Position): Promise<VimState> {
const isEndOfLine = end.character === end.getLineEnd().character;
const isBeginning =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Position has a function called isLineBeginning() - could you use that one?

end.isLineBeginning() &&
!start.isLineBeginning(); // to ensure this is a selection and not e.g. and s command
let state = vimState;

// If we delete to EOL, the block cursor would end on the final character,
// which means the insert cursor would be one to the left of the end of
// the line. We do want to run delete if it is a multiline change though ex. c}
if (Position.getLineLength(TextEditor.getLineAt(start).lineNumber) !== 0 || (end.line !== start.line)) {
if (isEndOfLine) {
if (isEndOfLine || isBeginning) {
state = await new DeleteOperator(this.multicursorIndex).run(vimState, start, end.getLeftThroughLineBreaks());
} else {
state = await new DeleteOperator(this.multicursorIndex).run(vimState, start, end);
Expand Down
9 changes: 8 additions & 1 deletion test/mode/modeVisual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ suite("Mode Visual", () => {
endMode: ModeName.Normal
});

newTest({
title: "Changes on a firstline selection will not delete first character",
start: ["test|jojo", "haha"],
keysPressed: "vj0c",
end: ["test|haha"],
endMode: ModeName.Insert
});

suite("D command will remove all selected lines", () => {
newTest({
title: "D deletes all selected lines",
Expand All @@ -656,6 +664,5 @@ suite("Mode Visual", () => {
end: ["first line", "|second line"],
endMode: ModeName.Normal
});

});
});