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 visual line selection from bottom to top. #307

Merged
merged 1 commit into from
Jun 17, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ typings
*.sw?
.vscode-test
.DS_Store
*.vsix
8 changes: 6 additions & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ export class DeleteOperator extends BaseOperator {
end = new Position(end.line, end.character + 1);
}

const isOnLastLine = end.line === TextEditor.getLineCount() - 1;

// Vim does this weird thing where it allows you to select and delete
// the newline character, which it places 1 past the last character
// in the line. Here we interpret a character position 1 past the end
Expand All @@ -490,13 +492,15 @@ export class DeleteOperator extends BaseOperator {
end = end.getDown(0);
}

// If we do dd on the final line of the document, we expect the line
// If we delete linewise to the final line of the document, we expect the line
// to be removed. This is actually a special case because the newline
// character we've selected to delete is the newline on the end of the document,
// but we actually delete the newline on the second to last line.

// Just writing about this is making me more confused. -_-
if (start.line === end.line && start.line !== 0 && vimState.currentRegisterMode === RegisterMode.LineWise) {
if (isOnLastLine &&
start.line !== 0 &&
vimState.effectiveRegisterMode() === RegisterMode.LineWise) {
start = start.getPreviousLineBegin().getLineEnd();
}

Expand Down
22 changes: 20 additions & 2 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ export class VimState {

public currentRegisterMode = RegisterMode.FigureItOutFromCurrentMode;

public effectiveRegisterMode(): RegisterMode {
if (this.currentRegisterMode === RegisterMode.FigureItOutFromCurrentMode) {
if (this.currentMode === ModeName.VisualLine) {
return RegisterMode.LineWise;
} else {
return RegisterMode.CharacterWise;
}
} else {
return this.currentRegisterMode;
}
}

public registerName = '"';

/**
Expand Down Expand Up @@ -537,8 +549,14 @@ export class ModeHandler implements vscode.Disposable {
}

if (this.currentModeName === ModeName.VisualLine) {
start = Position.EarlierOf(start, stop).getLineBegin();
stop = Position.LaterOf(start, stop).getLineEnd();
if (Position.EarlierOf(start, stop) === stop) {
[start, stop] = [stop, start];
}

start = start.getLineBegin();
stop = stop.getLineEnd();

vimState.currentRegisterMode = RegisterMode.LineWise;
}

return await recordedState.operator.run(vimState, start, stop);
Expand Down