Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Conversation

@jacekkopecky
Copy link
Contributor

Fixes #737.
Differs from VIM in that if the visual mode selection was characterwise over multiple lines, and the last line of the selection was longer than the corresponding line where we are redoing the operation, VIM would remove the newline and this PR doesn't. See #737 for more information on this.
Any comments will be welcome.

@bronson
Copy link
Contributor

bronson commented Jul 6, 2015

Very very impressive. I've banged on it, can't find anything wrong. As promised, it's in vim-mode-next 0.54.12.

Vim's charwise multi-line behavior feels like a bug. I definitely vote for your current behavior.

@DaanDD
Copy link

DaanDD commented Jul 9, 2015

I've been trying this in vim-mode-next (currently 0.54.15) and repeating commands in line wise visual mode doesn't seem to work correctly. For example, take this file:

foo
bar

Now select both lines with Vj and indent with >

  foo
  bar

When I try to repeat the command with . only the first line gets indented again.

    foo
  bar

@bronson
Copy link
Contributor

bronson commented Jul 9, 2015

Wow. I'm using 0.54.15 too and I don't see that. Both lines indent every time I hit ..

Silly question, you sure vim-mode didn't re-enable itself somehow?

@DaanDD
Copy link

DaanDD commented Jul 9, 2015

I tried it again with a clean install on a different computer and it still behaves as I described.

@jacekkopecky
Copy link
Contributor Author

I've just reproduced it - the problem shows up as described on a file with only two lines. Try this in a new file:
ifoo<cr>bar<esc>kVj>.
Strangely enough, it works with v instead of V, and it also works with an extra <cr> after bar and an extra k before V. I'll have to look into it. But I hope a fix for this can be another PR if this one can otherwise be merged - it seems to work well enough in situations where I've tried it. If this PR is merged, an issue for the strange behaviour should be opened.

@bronson
Copy link
Contributor

bronson commented Jul 9, 2015

Nice!! Yes, the missing newline on the last line must be the culprit. I'm seeing it too.

I've noticed that files that don't end in newlines trip up some other vim-mode operations too.

Copy link
Contributor

Choose a reason for hiding this comment

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

You might be able to use some more abstract methods on Point and Range to do this. Could you try something along these lines?

selectCharacters: ->
  lastSelectionExtent = @lastSelection.getExtent()
  for selection in @editor.getSelections()
    {start} = selection.getBufferRange()
    selection.setBufferRange([start, start.traverse(lastSelectionExtent)])
  return

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought: maybe if the motion @wasLinewise, we could use the same code path as for characters, but then call @editor.selectLinesContainingCursors(), or selection.selectLine() on each selection? Not sure if those methods have the right behavior in all cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An attempt just committed, @maxbrunsfeld .
Using Point.traverse doesn't do wrapping so that's extra, but still the code is nicer.
Doing selectLines with selectCharacters, with some linewise stuff around, would work but actually the special-cased code is faster and simpler, IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. I agree.

@jacekkopecky jacekkopecky force-pushed the fix-visual-selection-repeat branch from f3d2d6f to 3215561 Compare August 1, 2015 21:10
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain what this if wrap section is for again? I would think that when redoing visual mode operations, we'd always want to select the same number of lines as the original operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I misinterpreted what VIM was doing. When the last line of the original charwise selection has more characters than are available, VIM eats the newline and I thought it ate more than that. I'll fix it so that vim-mode doesn't eat the newline because I find it illogical behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll fix it so that vim-mode doesn't eat the newline because I find it illogical behaviour.

I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
(noticed your reply above, edited to remove "let me know if you should disagree with this divergence from VIM, @ maxbrunsfeld.")

maxbrunsfeld pushed a commit that referenced this pull request Aug 12, 2015
fix redoing visual mode operations with `.`
@maxbrunsfeld maxbrunsfeld merged commit f49f5b3 into atom:master Aug 12, 2015
@maxbrunsfeld
Copy link
Contributor

@jacekkopecky jacekkopecky deleted the fix-visual-selection-repeat branch August 12, 2015 22:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants