Skip to content
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

Implement Window/Page scroll commands #9609

Closed
3 tasks done
sandy081 opened this issue Jul 22, 2016 · 13 comments
Closed
3 tasks done

Implement Window/Page scroll commands #9609

sandy081 opened this issue Jul 22, 2016 · 13 comments
Assignees
Labels
api VIM VIM issue
Milestone

Comments

@sandy081
Copy link
Member

sandy081 commented Jul 22, 2016

These commands are needed for Vim:

From VSCodeVim/Vim#210:

Vim has handy commands for scrolling without moving the cursor, e.g. zt, which scrolls the screen so that the line with the current cursor is placed as the first line. E.g., I often do actions like /main(zt, so that I can see as much of the main function as possible.

Would it be possible to implement zt, zb and zz?

Thanks!

  • Scroll window upwards/downwards by lines (real line) or window size (eg, half window size)
executeCommand('editorScroll', {to: 'up', by: 'line', value: 10, revealCursor?: false});

'to'

  • up
  • down

'by'

  • line
  • wrappedLine
  • page
  • halfPage

'revealCursor'

  • If true reveals the cursor while scrolling otherwise does not.
  • Scroll line to a specific position of the window
executeCommand('revealLine', {lineNumber: 10, at: 'top'});

'at'

  • top
  • center
  • bottom
  • Scroll horizontal scrollbar by column numbers.
    Horizontal scrolling is already implemented by cursor move commands. Hence marking this done. See VIM API Gaps #8997
@sandy081 sandy081 added api VIM VIM issue labels Jul 22, 2016
@sandy081 sandy081 added this to the Backlog milestone Jul 22, 2016
@sandy081 sandy081 self-assigned this Jul 22, 2016
@sandy081 sandy081 mentioned this issue Jul 22, 2016
4 tasks
@rebornix
Copy link
Member

rebornix commented Jul 28, 2016

About the first task, just realized that we have scrollLineUp scrollLineDown, scrollPageUp and scrollPageDown commands already. The only part missing is scrolling half page down.

Users are allowed to scroll line up or down with numeric prefix, like 10 Ctrl-E to scroll ten lines down. If we repeat scrollLineUp ten times, I'm worried we might have performance hit somehow. So a generic command takes line number as argument will be better IMHO.

@sandy081
Copy link
Member Author

sandy081 commented Aug 4, 2016

@rebornix Delivered a new command called editorScroll. Try it and let me know the feedback. See the description for usage.
Thanks

@rebornix
Copy link
Member

rebornix commented Aug 8, 2016

@sandy081 I just ran your commands but see below errors

error.stack
Error: argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true
    at f (file:///C:/Program Files (x86)/Microsoft VS Code Insiders/resources/app/out/vs/workbench/workbench.main.js:29:13605)

any idea?

@sandy081
Copy link
Member Author

@rebornix Hmm strange, I do not see any issue while using this command in our sample Vim extension. Can you show me how are you calling this command?

@rebornix
Copy link
Member

@sandy081 I just simply called await vscode.commands.executeCommand('editorScroll', {to: 'up', by: 'line', value: '1'});. This error occurs always on 1.5.0-Insider.

@rebornix
Copy link
Member

rebornix commented Aug 16, 2016

Finally I saw the problem. I'm not using the value of to correctly, I thought to: 'up' will move current line move upwards but actually it will move the line downwards. It behaves the same as Vim.

The only problem left is scrolling down the window await vscode.commands.executeCommand('editorScroll', {to: 'down', by: 'line', value: '1'}); doesn't work on the first line in the screen.

I guess you disable scrolling downwards the window on the first line as this command is not cursor moving and if we allow this command on the first line, the cursor will be out of current viewport, right? However Vim's behavior on this is scrolling lines/pages without moving cursor, if the final viewport doesn't contain the original line, Vim will put the cursor on the beginning of the nearest visible line in viewport.

@sandy081
Copy link
Member Author

@rebornix editorScroll command does not disable any scrolling in the above scenario. It just scrolls the window up or down irrespective of the cursor position. It does not reposition the cursor if it goes outside view port. I think this is beyond the scope of command's functionality.

@rebornix
Copy link
Member

@sandy081 that's what I'm seeing, now I reposition the cursor in VSCodeVim's code and it works well. The only issue I see is scrolling doesn't work on first line, can you help confirm?

sandy081 added a commit that referenced this issue Aug 18, 2016
sandy081 added a commit that referenced this issue Aug 19, 2016
@sandy081
Copy link
Member Author

@rebornix Enhanced editorScroll command to reveal cursor while scrolling. See the description for syntax and how to use.

Also implemented revealLine command to reveal the line at the given logical position in the screen. Again see the description for usage.

@rebornix
Copy link
Member

rebornix commented Aug 23, 2016

@sandy081 Played with revealLine not sure I'm doing correctly but when I run await vscode.commands.executeCommand('revealLine', {lineNumber: 1, at: 'top'});, the window scroll down by 1 line and the cursor doesn't move. The cursor behavior is expected but seems top is not working. I suppose 'revealLine', {lineNumber: 1, at: 'top'} will move current line to the top first line in the window, right?

BTW, I'm checking the result of this command by setting breakpoint before and after this line, so there should be other side effect by VSCodeVim.

@sandy081
Copy link
Member Author

@rebornix Yeah, please check if there is some side effect from Vim extension, because this was working properly in the sample.

@nschurmann
Copy link

Great, where do i write this config?

@rebornix
Copy link
Member

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api VIM VIM issue
Projects
None yet
Development

No branches or pull requests

3 participants