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

Some visual block fixes #667

Merged
merged 5 commits into from
Sep 3, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -6,3 +6,4 @@ node_modules
*.vsix
*.log
testing
.vscode/
30 changes: 25 additions & 5 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,11 @@ export class DeleteOperator extends BaseOperator {
// 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
// as selecting the newline character.
if (end.character === TextEditor.getLineAt(end).text.length + 1) {
end = end.getDown(0);
// as selecting the newline character. Don't allow this in visual block mode
if (vimState.currentMode !== ModeName.VisualBlock) {
if (end.character === TextEditor.getLineAt(end).text.length + 1) {
end = end.getDown(0);
}
}

// If we delete linewise to the final line of the document, we expect the line
Expand Down Expand Up @@ -2685,8 +2687,26 @@ class ActionChangeInVisualBlockMode extends BaseCommand {
public async exec(position: Position, vimState: VimState): Promise<VimState> {
const deleteOperator = new DeleteOperator();

// Check to see number in lines of block
let blockLines = 0;
let blockStart = position;
let blockEnd = position;
for (const {start, end} of Position.IterateLine(vimState)) {
blockStart = start;
Copy link
Member

Choose a reason for hiding this comment

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

Won't these two variables be reassigned every time you go through the loop?

blockEnd = end;
blockLines += 1;
}

// Do a regular visual 'change' if only 1 line of block is selected
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have to special case this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will remove the special case and improve the insert block mode a little bit more, visual block is just a little funky, I will try to fix the root funkiness there instead of this way

if (blockLines < 2) {
await new DeleteOperator().run(vimState, blockStart, blockEnd.getLeft());
vimState.cursorPosition = vimState.cursorStartPosition;
vimState.currentMode = ModeName.Insert;
return vimState;
}

for (const { start, end } of Position.IterateLine(vimState)) {
await deleteOperator.delete(start, end, vimState.currentMode, vimState.effectiveRegisterMode(), vimState, true);
await deleteOperator.delete(start, end.getLeft(), vimState.currentMode, vimState.effectiveRegisterMode(), vimState, true);
}

vimState.currentMode = ModeName.VisualBlockInsertMode;
Expand Down Expand Up @@ -2786,7 +2806,7 @@ class InsertInInsertVisualBlockMode extends BaseCommand {

posChange = -1;
} else {
await TextEditor.insert(this.keysPressed[0], insertPos.getLeft());
await TextEditor.insert(this.keysPressed[0], insertPos);

posChange = 1;
}
Expand Down