-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[vim keymap] Visual mode rewrite and other changes #1262
Conversation
- visual mode now behaves more vim-like - handling special keys better for commands requiring a character - r can operate on selection - +/-/_ via new moveByLinesToFirstNonWhiteSpaceCharacter motion
Great! @mightyguava I'd like you to glance over this again (if you don't have time for these reviews, let me know, I'll stop notifying you.) |
Sorry for the delay. I was away for the long weekend. The new visual mode looks vastly superior to the previous version. Thanks! If you want to merge Regarding the custom selection function. I strongly agree that that changing CodeMirror's internal state here is bad. A rule I followed implementing |
Now I feel stupid. I'll do just that. Any idea how I could improve the handling of 0-based repeat on Also: would you mind if I rename As for the detection for mouse interaction, I've restored that for now, but I hope I can take a stab at solving #1084 the way @marijnh suggests soon. This might result in some tools to handle various mouse-related issues and also help with solving #1038. |
Sorry, don't have a better idea. I find
Sure. The text object manipulation motion is a bad hack I threw in to carry over the functionality from the original
Sounds great. I didn't do it earlier because the fix would be v3 specific and somewhat involved. At this point, keeping |
I just looked through it while trying to improve I merged the two motions, and added two small fixes in another patch. One was an oversight by me ( Since you mention v2, how relevant is support for the version? I'm not too familiar with how CodeMirror is used by others so I hope I'm not ignorantly trampling on anything here. |
I don't have a clear grasp of what the selection problem you're having is like, exactly. Just an idea -- would a |
Should I merge the patches here as they stand, by the way, or is there going to be more adjustment? |
The idea of
As I've written in the notes on visual mode, there are a few differences between vim-selection and the default selection handling. The short version: it covers at least one additional character at the end, and sometimes more in both directions (moving You can also try the vim-demo if you prefer that, press While what I do works whenever I am actively setting selection, a few areas are out of reach this way (namely click/drag and undo). The vim-keymap does not register for any events at this point, but I'm planning to try your suggestion from #1084 soon. What I like about As for the merge it depends on whether @mightyguava likes the current state and the way I implemented his suggestions. Especially he might not want the workaround of reimplementing |
+1 vote for something like beforeSelectionChange - that definitely has uses on my end as well. |
👍 for |
If it would be safe to modify
Ah didn't know you were waiting on me for this. If @marijnh will be adding |
There's an invariant that from/to always correspond to anchor/head (from to the lesser one, to to the greater). This invariant is not going away. |
Ok, that kicks my approach out of the window. I understand that you don't want to risk stability issues you'd have to deal with though, I'll see if I can get my changes to visual mode out again so the remaining ones can be merged. |
@mightyguava are you ok with how the patch looks right now? In that case I'd suggest a merge as
Also I'd like you to take a look at d776f74 if you're interested. There I played around with making the selection right but the (now hidden) cursor wrong. |
I've merged the changes as they stand. (I somehow missed the horrible things you were doing in your |
You're right, the original commit would have better just been an use-case. I should have opened a normal Issue first to ask whether |
My second batch of changes, containing the remaining additions from my local setup. Should also fix some problems discussed in Issue #1246.
Changes
moveByLinesToFirstNonWhiteSpaceCharacter
, used to implement the motions+
(move{repeat}
lines down, then to the first non-whitespace-character on that line),-
(same for up) and_
(same as+
but with repeat reduced by 1, so with a repeat of 1 it behaves like^
).Enter
,Space
orDown
) would pass it on as string (see Issue vim mode 'r <Enter>' keeps replace mode active #1246). These keys are now converted to a printable character if possible and rejected otherwise.r{character}
replaces all individual characters in the selection by{character}
, while leaving linebreaks intact. Special case as by vim help is\n
as{character}
, which creates only one linebreak for anr
operation.DIY-Example: Inputting
ggOTitle<Esc>yypVr=
(with<Esc>
being the escape-key) should now behave just as it does in vim.Notes on moveByLinesToFirstNonWhiteSpaceCharacter
I'm on the fence about whether to keep
moveByLinesToFirstNonWhiteSpaceCharacter
or merge it withmoveToFirstNonWhiteSpaceCharacter
. Merging means there would be one less motion, but instead one with anif
at the start picking between the two code paths. I also find the name to be obscenely long. @mightyguava what would you prefer here?Notes on visual mode (selection)
Vim's cursor is not between characters but on one. This also has implications on the selection model. For the beginning of the selection the left side of the cursor is used, while for the end it is the right side. This requires
sel.to
to be incremented by 1 from the position CodeMirror'ssetSelection
would place it at. Even more of a special case is linewise selection. Heresel.from
is moved to the first character of the line, whilesel.to
is moved behind the last one.CodeMirror as it is doesn't seem to require
sel.from
andsel.to
to be eithersel.anchor
orsel.head
. I'm not sure if I should expect this special case to be stable and especially whether I really want you to maintain this rather exotic use-case. I am replicatingsetSelection
's behavior for now in an own function (vim.js:1511) and adapt the values at the end. From my testing it seemed to work out quite well. Obviously it cannot deal with folding yet, since I cannot accessskipAtomic
from my code (a hacky workaround would be callingsetCursor(curEnd)
or something similar before the custom operation). The only other problem I ran into is how CodeMirror restores selection on undo, which is a separate issue I'll look into as well. Also of course replicating internal code is really bad, I'll try to think of a way that doesn't need much change to the API but still allows me to get the core-code out of mysetSelection
.I made one change to
codemirror.css
. The reason is that settingshowCursorWhenSelecting
doesn't help if the cursor is covered by the selection (selection hasz-index
set to 1).