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

Fixes #890, #1377: Selection (both visual/visualline) is very wonky with gj and gk #1600

Merged
merged 7 commits into from
Apr 30, 2017

Conversation

Chillee
Copy link
Member

@Chillee Chillee commented Apr 28, 2017

I think this fixes all the visual selection related bugs I could find.

@@ -3673,6 +3673,11 @@ abstract class MoveByScreenLine extends BaseMovement {
value: number = 1;

public async execAction(position: Position, vimState: VimState): Promise<Position | IMovement> {
if (vimState.currentMode === ModeName.VisualLine) {
Copy link
Member

Choose a reason for hiding this comment

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

Could we have a quick comment here to say why this is necessary (or which issue it is fixing)?

Copy link
Member Author

@Chillee Chillee Apr 29, 2017

Choose a reason for hiding this comment

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

So the main issue is that we don't handle visualLine selections, due to the fact that our cursor must be at either start or stop (which as far as I can tell, works for every case but this one?). Well, I think that's true of IMovements at least.

However, in vim in visual line mode, doing gj on a wrapped line causes you to maintain the same highlighted area, however, your cursor is moved up one wrapped line.

However, we always snap the cursors at the beginning and the end of the selection to the end of the line (to maintain visual line mode). Thus, if we do a "gj" on a wrapped line, we are snapped back to our initial position, and we can't move down.

I don't think there's a good solution for this, so the workaround I came up with was to move by a "line" instead of a "wrappedLine" if you're doing visualLine movement.

This behavior doesn't exactly match vim, but I really doubt (I hope) that anybody relied on that feature of vim, since you can't select by screen lines anyways.

Copy link
Member Author

@Chillee Chillee Apr 29, 2017

Choose a reason for hiding this comment

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

Hmm, actually.

Maybe it is possible? The vscode.selection objects have a start, stop and active attribute. The problem (I think) is that the way we represent cursors only has a start and stop.

@johnfn
Copy link
Member

johnfn commented Apr 29, 2017

Again, thank you so much for the bevy of PRs recently. Much appreciated. :)

// and moving by screen line just snaps us back to the original position.
// Check PR #1600 for discussion.
if (vimState.currentMode === ModeName.VisualLine) {
if (this.movementType === "up" || this.movementType === "down") {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of putting this filter here. Each non-abstract extended MoveByScreenLine defines its movementType, if the logic is only related to it, then we may want to put it in that extended class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it's better to define another class "MoveUpByScreenLineVisualLine"?

Copy link
Member

Choose a reason for hiding this comment

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

oh that would be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

The new commit should have done that.

@johnfn johnfn merged commit 33b0838 into VSCodeVim:master Apr 30, 2017
@Chillee Chillee changed the title Fixes #890, #1377 Fixes #890, #1377: Selection (both visual/visualline) is very wonky with gj and gk May 2, 2017
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants