-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Added new commands to allow finer-grain line navigation #9220
Conversation
Hi @TanukiSharp, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
@TanukiSharp, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
Hi @TanukiSharp, firstly I am impressed with the description provided by you here. Steps are very organized and descriptive and explains what is being done clearly. It is a good idea to have commands for navigating cursor to logical screen positions of the line. These are very much needed for various use cases. As part of our July Iteration Plan, we are enhancing our editor by providing commands to the extension developers, through which they can perform some screen motions on the editor which cannot be done through API. This is mainly driven for VIM editor extension. Please refer to this Evaluate API gaps for better VIM support for more information. Coincidentally, work we are doing for this feature is overlapping with this pull request. I am implementing a single command So, please go through our plan, design and implementation and let us know if they suit your requirements and we can discuss on how to move forward. Thanks a lot for bringing good ideas. |
Hello @sandy081 Sorry for late reply, and thank you for your review and information. I've checked the content of July iteration plan and other pull requests / issues, looks great. Thank you. |
@TanukiSharp Please don't do any more work on this PR for now. We plan to add |
I see, thank you very much for your update, because I was kind of wondering what to do next. |
The CI fails due to https://travis-ci.org/Microsoft/vscode/jobs/144503630#L2089
Most likely your changes resulted in a new monaco editor API shape (contained in monaco.d.ts and you did not stage that file). |
I believe the initial reason for adding these commands has been mitigated by our various tweaks for home and end, where e.g. end stops first at the wrapped line end, and then at the model line end. |
This PR propose a change to allow more behaviors for the line navigation feature, through new keyboard shortcut commands.
The problem
Now pressing
Home
andEnd
keys makes the cursor move to the first/last non white space character first, then to the real beginning/end of line, and so forth. This makes VSCode behave like WebStorm for example, however I would like to be able to make it behave like Visual Studio.Home
goes to the first non white space character, then goes to the very beginning of the lineEnd
goes to the last non white space character, then goes to the very end of the lineHome
goes to the first non white space character, then goes to the very beginning of the line (same as WebStorm)End
just go to the the very end of the lineUntil then, I could not find the way to setup VSCode and make it behave like Visual Studio, that's why I propose a change.
The proposal
First, I believe a bit a terminology is required in order to be sure that we are all on the same page.
If the vocabulary I use is not correct, please let me know.
Terminology
What I call the visual boundaries of a line, is the line not including the white space characters, so simply said, the visual boundaries of a line go from the first 'visible' character to the last 'visible' character.
The logical boundaries of a line is the whole line, including all the characters from the beginning to the first line separator character, including white spaces.
Example:
New cursor commands
To be able to change the line navigation behavior, and still let other people configure it the way they want, I added new cursor commands. Existing ones are
CursorHome
andCursorEnd
(along with their*Select
related command).For the ones interested, they can be found through the menu
File
/Preferences
/Keyboard Shortcuts
, then this way:I added the following new commands:
Cursor*VisualThenLogical
Cursor*LogicalThenVisual
Cursor*VisualOnly
Cursor*LogicalOnly
where '*' is
Home
andEnd
, and of course their*Select
related commands, making a total of 16 new commands.Note that
CursorHomeVisualThenLogical
is simply an alias to existingCursorHome
, and the same goes forCursorEndVisualThenLogical
aliasingCursorEnd
, since this is the default behavior of VSCode.The new commands appear in the list at the bottom of the keyboard shortcuts configuration file as other available commands.
Unit tests
I added new unit tests (all passing) for each combination of commands and contexts.
Those are in the file
cursor.test.ts
.Linting
When I ran the
tslint
command, some reports appeared, but none concerning the change I made, so should be fine.Combination of cases
I've tested the change, and it works in all line navigation modes, including all combination or selection, wrapped lines and multi cursor contexts.
monaco editor
I had to modify
monaco.d.ts
in order to add new handlers, however I'm not sure if I'm supposed to do that, neither if I'm supposed to do it that way. I tried to find the code I needed to change in the monacor-editor related GitHub repositories, but I could not find what I was looking for.Visual Studio like setup
Do not forget to set the
*Select
version, or you may experience asymmetries.