Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix various issues with
SpawnMultiCursor{Up,Down}
(#3145)
* SpawnMultiCursorUp/Down: change order of adding cursors SpawnMultiCursor{Up,Down} currently works in a tricky way: instead of creating a new cursor above or below, it moves the current "primary" cursor above or below, and then creates a new cursor below or above the new position of the current cursor (i.e. at its previous position), creating an illusion for the user that the current (top-most or bottom-most) cursor is a newly spawned cursor. This trick causes at least the following issues: - When the line above or below, where we spawn a new cursor, is shorter than the current cursor position in the current line, the new cursor is placed at the end of this short line (which is expected), but also the current cursor unexpectedly changes its x position and moves below/above the new cursor. - When removing a cursor in RemoveMultiCursor (default Alt-p key), it non-intuitively removes the cursor which, from the user point of view, is not the last but the last-but-one cursor. Fix these issues by replacing the trick with a straightforward logic: just create the new cursor above or below the last one. Note that this fix has a user-visible side effect: the last cursor is no longer the "primary" one (since it is now the last in the list, not the first), so e.g. when the user clears multicursors via Esc key, the remaining cursor is the first one, not the last one. I assume it's ok. * SpawnMultiCursorUp/Down: move common code to a helper fn * SpawnMultiCursorUp/Down: honor visual width and LastVisualX Make spawning multicursors up/down behave more similarly to cursor movements up/down. This change fixes 2 issues at once: - SpawnMultiCursorUp/Down doesn't take into account the visual width of the text before the cursor, which may be different from its character width (e.g. if it contains tabs). So e.g. if the number of tabs before the cursor in the current line is not the same as in the new line, the new cursor is placed at an unexpected location. - SpawnMultiCursorUp/Down doesn't take into account the cursor's remembered x position (LastVisualX) when e.g. spawning a new cursor in the below line which is short than the current cursor position, and then spawning yet another cursor in the next below line which is longer than this short line. * SpawnMultiCursorUp/Down: honor softwrap When softwrap is enabled and the current line is wrapped, make SpawnMultiCursor{Up,Down} spawn cursor in the next visual line within this wrapped line, similarly to how we handle cursor movements up/down within wrapped lines. * SpawnMultiCursorUp/Down: deselect when spawning cursors To avoid weird user experience (spawned cursors messing with selections of existing cursors).
- Loading branch information