-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from 2 commits
4f945cd
292426c
cee09f7
0d102fd
b7ab9d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules | |
*.vsix | ||
*.log | ||
testing | ||
.vscode/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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; | ||
blockEnd = end; | ||
blockLines += 1; | ||
} | ||
|
||
// Do a regular visual 'change' if only 1 line of block is selected | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have to special case this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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; | ||
} | ||
|
There was a problem hiding this comment.
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?