-
Notifications
You must be signed in to change notification settings - Fork 249
fix redoing visual mode operations with .
#740
fix redoing visual mode operations with .
#740
Conversation
|
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. |
|
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: Now select both lines with When I try to repeat the command with |
|
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? |
|
I tried it again with a clean install on a different computer and it still behaves as I described. |
|
I've just reproduced it - the problem shows up as described on a file with only two lines. Try this in a new file: |
|
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. |
4be8838 to
f3d2d6f
Compare
lib/motions/general-motions.coffee
Outdated
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.
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)])
returnThere 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.
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.
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.
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.
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.
Got it. I agree.
suggested by @maxbrunsfeld , thanks
f3d2d6f to
3215561
Compare
lib/motions/general-motions.coffee
Outdated
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.
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.
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.
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.
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.
I'll fix it so that vim-mode doesn't eat the newline because I find it illogical behaviour.
I agree.
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.
Done.
(noticed your reply above, edited to remove "let me know if you should disagree with this divergence from VIM, @ maxbrunsfeld.")
fix redoing visual mode operations with `.`
|
✨ |
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.