-
Notifications
You must be signed in to change notification settings - Fork 28.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
Introduce a move command for moving cursor in the editor #9143
Comments
@rebornix I am going to implement a command name 'move' which can take arguments. Based on the arguments command will move the cursor appropriately. Let me know if you have any specifications so that I can make them part of it. As a beginning, this will let to move the cursor to
|
Is this what you need? // set anchor=active for just positioning the cursor (no selection)
editor.selections = [new vscode.Selection(anchor, active)] |
// set anchor=active for just positioning the cursor (no selection)
editor.selections = [new vscode.Selection(anchor, active)] @siegebell No, above will place the cursor as per the editor model. Instead this new command will allow you to move it to a position you wanted on the screen. For eg: If a line is wrapped and if you want to move the cursor to the beginning of the line on the screen (not to the beginning of the complete line) above javascript will not able to do that. |
@sandy081 Ah, you want screen-relative coordinates. Good idea. But I would find a function that translates screen coordinates into a |
@siegebell We can but this will introduce view properties on the text editor model which is not a good idea. Hence we intended to provide commands so that users can execute them. |
@sandy081 these commands look good to me and really thank you! For now I still need time to check whether they are suitable to Vim integration, whether it's a direct support or a workaround. |
@sandy081 just played around with these APIs, thank you very much as they make the implementation really simple our side. I bet other extensions can also benefit from these APIs. There is some unexpected behaviors while running Another one is |
@rebornix I see |
@rebornix Yah, I forgot to update the description with updated keywords. Thanks for pointing this. |
@rebornix It would be great if you can give me an updated list of VIM commands (all variations) which are implemented / implementable (with existing API) and which are still not. I have seen the VIM extension road map but I think it is not up to date or does not have all variations.. we can also discuss it offline. Thanks |
@rebornix Commands |
@sandy081 I just found that Vim's |
@rebornix above commands are moving to Screen line not to real line. Can you please check by having a very small wrapping size. I think the issue you are seeing is if the screen line above top screen line is little visible then H command jumps to that. Also there is a similar issue for bottom of the view - #9542. It looks to me an issue while computing the lines layout. Since Alex is on vacation we have to wait on that. Otherwise, |
Adopt to the above changes and let me know the feedback. Thanks |
@rebornix Please note the small change done to the API for consistency and clean
Please adopt to these changes |
@sandy081 await vscode.commands.executeCommand("cursorMove", {
to: "up",
by: "wrappedLine",
select: true,
value: count
}); I've spent a couple of hours on this, it seems that @sandy081 Please give us the same API without moving the cursor, Vim extensions are masters on how to move the cursor themselves. |
@sandy081 This is how we can practically use your api, Let's face it, no other plugin is going to use these commands other than VIM extensions 😉 These makes both vim extension writer life and vscode team easier. |
I would like to chime in along with @aminroosta here. Unfortunately, the current cursorMove API is not powerful enough to implement most core features of Vim. Simply moving the cursor is not enough - we actually need the position. Without the position, there's no practical way to use the value any of the visual modes (which effectively take the position, then apply some transformations on it, and then create a new selection object). This means that visual mode, visual line mode and visual block mode cannot be implemented using this API. Again, we are all super appreciative of all the work that you guys do on such a great editor. Let us know if there's anything we can do to help! |
It is working for me very smoothly. Please see the attached video. I call the following command just like you did vscode.commands.executeCommand("cursorMove", {
to: "up",
by: "wrappedLine",
select: true,
value: count
});
@rebornix, In regards to @johnfn comment, may I know what is missing here? I remember that this can be used to implement most of cursor movement functionality in Vim. In fact, I implemented in our Vim sample extension. |
@sandy081 Thanks for taking time and checking this issue. So there should be something wrong with my code. If your code is available online on github please let me know. |
@aminroosta here is our Vim sample extension. |
@sandy081 |
@sandy081 It seems only lower case |
@aminroosta Just to note that the sample vim extension does not have all complete vim features. This is an example/reference implementation showing how some of the vim features can be implemented using the editor commands. With regards to @rebornix might help you in how to consume this. |
@sandy081 thanks for the tip. @aminroosta I'm adding these command sin my separate PR but it does hacking to the view updating phase so it's still WIP. I'll let you know if I solve the issues you met. |
I see the problem, I only used |
Introduce a move command for moving cursor at a logical view position in the editor
This will allow the extension writers to place the cursor at a provided position in the editor
Usage:
cursorMove
{to: $ViewPosition, select: boolean, by: $By, value: number}
value
= 1.by
based onto
value.ViewPosition
left
: Moves the cursor left byn
characters.right
: Moves the cursor right byn
characters.up
: Moves the cursor up byn
lines or wrapped lines.down
: Moves the cursor down byn
lines or wrapped lines.wrappedLineStart
: Places the cursor at the start of the current line in the view.wrappedLineFirstNonWhitespaceCharacter
: Places the cursor at the first non white space character of the current line in the view.wrappedLineEnd
: Places the cursor at the end of the current line in the view.wrappedLineLastNonWhitespaceCharacter
: Places the cursor at the last non white space character of the current line in the view.wrappedLineColumnCenter
: Places the cursor at the center of the line in the view.viewPortTop
: Move the cursor to the first non white space character of Nth line from the top of the view.viewPortCenter
: Move the cursor to the first non white space character of the center line of the view.viewPortBottom
: Move the cursor to the first non white space character of Nth line from the bottom of the view.By
line
- Default for line specific commandswrappedLine
character
- Default for character specific commandshalfLine
- Only for character specific commands.Set
select
arg totrue
, to select text for aboveThe text was updated successfully, but these errors were encountered: