Revert SpawnMultiCursor{Up,Down} honoring softwrap + overhaul LastVisualX usage#3503
Conversation
Since we already have the StoreVisualX() helper, use it all over the place instead of setting LastVisualX directly. This will allow us to add more logic to StoreVisualX() add let this extra logic apply everywhere automatically.
Restore the original meaning of LastVisualX before commit 6d13710 ("Implement moving cursor up/down within a wrapped line"): last visual x location of the cursor in a logical line in the buffer, not in a visual line on the screen (in other words, taking tabs and wide characters into account, but not taking softwrap into account). And add a separate LastWrappedVisualX field, similar to LastVisualX but taking softwrap into account as well. This allows tracking last x position at the same time for both cases when we care about softwrap and when we don't care about it. This can be useful, for example, for implementing cursor up/down movement actions that always move by logical lines, not by visual lines, even if softwrap is enabled (in addition to our default CursorUp and CursorDown actions that move by visual lines). Also this fixes a minor bug: in InsertTab(), when `tabstospaces` is enabled and we insert a tab, the amount of inserted spaces depends on the visual line wrapping (i.e. on the window width), which is probably not a good idea.
In cursor's Goto(), which is currently only used by undo and redo, we restore remembered LastVisualX and LastWrappedVisualX values. But if the window had been resized in the meantime, the LastWrappedVisualX may not be valid anymore. So it may cause the cursor moving to unexpected locations. So for simplicity just reset these values on undo or redo, instead of using remembered ones.
Commit 9fdea82 ("Fix various issues with `SpawnMultiCursor{Up,Down}`") changed SpawnMultiCursorUp/Down actions to honor softwrap, i.e. spawn cursor in the next visual line within a wrapped line, which may not be the next logical line in a buffer. That was done for "consistency" with cursor movement actions CursorUp/Down etc. But it seems there are no actual use cases for that, whereas at least some users prefer spawning multicursor in the next logical line regardless of the softwrap setting. So restore the old behavior. Fixes micro-editor#3499
c23ebe8 to
e6ed161
Compare
|
By intention: the next commit 6214abb changes those 2 places to set Hmm... it just occurred to me that it means that in those 2 places, i.e. when we resize the window or enable/disable softwrap, we "reset" cursor up/down movements if softwrap is enabled (i.e. when |
Ah, I see. Was interrupted for a long time right after the review of the first commit and thus didn't realize that.
Is it worth documenting this there, just for faster realization? |
At the moment I'm inclined to think it's better to leave this without documenting, this is of too little importance to draw attention to it with a comment in the code (perhaps no real user will ever pay attention to this subtle difference in behavior), and if we ever need to think about this again, it shouldn't be difficult to figure out from the code what's going on. |
|
Ok, does work so far as intended and PS: |
Just because we also have
What does |
I understand, just because of the consistency. Well, then we go again with this ugly name.
It spawns multiple cursors by clicks and does this in soft-wrapped visual lines too, which is what we prevent, when we do it with the keyboard only in the same scenario. For me it's inconsistent, but maybe I don't get it again...as so often. |
I don't find it particularly ugly. It is "move N lines up", where N may be negative.
We don't prevent spawning multicursors in soft-wrapped visual lines (why would we?), we just prevent spawning multicursors in the same logical line, when using In other words, we just ensure that in cases like the following: when the cursor is on the slash after |
|
|
Hm, yes. I was more thinking about the block-selection scenario (with the mouse), which
You're right, nothing. Forget about it. |





In #3145, namely in 9f36c57, we changed the behavior of
SpawnMultiCursor{Up,Down}to spawn cursor in the next visual line within a wrapped line when softwrap is enabled. That was done for "consistency" with cursor movements (Cursor{Up,Down}etc). However it seems there are no actual use cases for that. Whereas at least some users (see issue #3499) prefer to spawn cursor in the next logical line, regardless of the softwrap setting.So restore the old behavior.
In the future we may also consider adding actions like
CursorUpLogical,CursorDownLogicaletc, for moving cursor by logical lines even if softwrap is enabled, if there are users that want it. For now let's just fix multicursor spawning....That is just a part of the story. Simply reverting 9f36c57 is not enough, since it would make
SpawnMultiCursor{Up,Down}broken, due to another change from #3145, namely 93b5326, due to the fact thatLastVisualXcurrently assumes visual lines, not logical lines, so mixing logical lines usage withLastVisualXusage would causeSpawnMultiCursor{Up,Down}spawn cursors at unexpected locations in some cases.The easy way would be to revert 93b5326 as well, but that means bringing back the issues fixed by 93b5326, which would be unfortunate.
So instead rework
LastVisualXandGetVisualX()usage: restore the original semantics ofLastVisualXthat it used to have long ago, before #2076: last visual x cursor location in a logical line, not in a visual line. And add a separateLastWrappedVisualXfield for last visual x cursor location in a visual line. So we can track last x position at the same time for both cases when we care about softwrap (e.g. cursor movements) and when we don't care about it (e.g. for spawning multicursors, in order to fix #3499, and possibly in the future forCursor{Up,Down}Logicaletc).Also this fixes a minor bug: in InsertTab(), when
tabstospacesis enabled and we insert a tab, the amount of inserted spaces depends on the visual line wrapping (i.e. on the window width), which is probably not a good idea.Fixes #3499