-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix various issues with SpawnMultiCursor{Up,Down}
#3145
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
To avoid weird user experience (spawned cursors messing with selections of existing cursors).
shkschneider
pushed a commit
to shkschneider/macro
that referenced
this pull request
Mar 5, 2024
* 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).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix various issues with spawning multicursors via
SpawnMultiCursorUp
andSpawnMultiCursorDown
actions (Alt-Shift-Up
andAlt-Shift-Down
):Current behavior:
![image](https://private-user-images.githubusercontent.com/147101/306095499-f9d73b82-d508-4eea-91b7-8ebf917485ef.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMjE3OTMsIm5iZiI6MTczOTIyMTQ5MywicGF0aCI6Ii8xNDcxMDEvMzA2MDk1NDk5LWY5ZDczYjgyLWQ1MDgtNGVlYS05MWI3LThlYmY5MTc0ODVlZi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQyMTA0NTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT01YzlkNGFiMmViNDM4MTJlOGViOTc0ODNlZDVkYjU3MWZkMWYzZDUwOTc4MTM4YTE1YTZiZjBjYjE3ZTBjMDk5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.1WZKzGQsTyhWP6epJpdA0XkpB2RUUAoISiHb5gNOtNs)
![image](https://private-user-images.githubusercontent.com/147101/306095523-5e73cb37-3767-404d-9611-9994f0c0ac6f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMjE3OTMsIm5iZiI6MTczOTIyMTQ5MywicGF0aCI6Ii8xNDcxMDEvMzA2MDk1NTIzLTVlNzNjYjM3LTM3NjctNDA0ZC05NjExLTk5OTRmMGMwYWM2Zi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQyMTA0NTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xZjA3N2ZiODZiMTMzNWQ0M2QyZjA5NTlhYzdkNGYxNjFkYjAxZWJkN2YwN2ZiZjdiYTJjZjVhYmJlMmM3Zjg0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Tc9Z1C5j-z8Fr8WtRpiZy-ZsXeqThGBie2-ZTSuql4s)
Expected behavior:
Current behavior:
![image](https://private-user-images.githubusercontent.com/147101/306095869-6af0bdec-c9b3-47d0-99bb-eafd7fd358ca.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMjE3OTMsIm5iZiI6MTczOTIyMTQ5MywicGF0aCI6Ii8xNDcxMDEvMzA2MDk1ODY5LTZhZjBiZGVjLWM5YjMtNDdkMC05OWJiLWVhZmQ3ZmQzNThjYS5wb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lgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Z1Znnkw3f78DMG5CohGdMivIgXWmJ2CfNH8UljOyh-0)
Expected behavior:
LastVisualX
not respected:Current behavior:
![image](https://private-user-images.githubusercontent.com/147101/306096117-c97e0a6c-fe41-4de3-aa4b-4693c6a7fd4f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMjE3OTMsIm5iZiI6MTczOTIyMTQ5MywicGF0aCI6Ii8xNDcxMDEvMzA2MDk2MTE3LWM5N2UwYTZjLWZlNDEtNGRlMy1hYTRiLTQ2OTNjNmE3ZmQ0Zi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQyMTA0NTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNjQ5MDMzYmJiYTA0MGU2MGFlYjk3YzYyYjJkMmZmZjY1YzRjMDZlNjJkY2JlODM0Y2EzNTJiNTdiZGJkZGQzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.dvzKnud2TMYj8PUJrWxvs7NI51NdR9i6pu9dNTDPoWU)
![image](https://private-user-images.githubusercontent.com/147101/306096128-b338c9fa-4f60-49a9-8f3e-27af0b948e6f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMjE3OTMsIm5iZiI6MTczOTIyMTQ5MywicGF0aCI6Ii8xNDcxMDEvMzA2MDk2MTI4LWIzMzhjOWZhLTRmNjAtNDlhOS04ZjNlLTI3YWYwYjk0OGU2Zi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMFQyMTA0NTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zMTY3MmMwODZhODA1NGMyZDVkMGVmNWU5NmI5NTMyY2IwMzM0Y2FhZWViMGRiOTFmNTZlMmQ3NGRlZmRkMzdiJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.6_oc30YEHNKFT3Lzax52te2za3ILeHOkuNJ9G0I64Q0)
Expected behavior:
RemoveMultiCursor
action (Alt-p
key) removes not the last spawned cursor but the last one before it.