Skip to content

Implement Window/Page scroll commands #9609

Closed

Description

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

Activity

  1. rebornix commented on Jul 28, 2016

    @rebornix
    Contributor

    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.

  2. sandy081 commented on Aug 4, 2016

    @sandy081
    MemberAuthor

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

  3. rebornix commented on Aug 8, 2016

    @rebornix
    Contributor

    Sandeep Somavarapu (@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?

  4. sandy081 commented on Aug 15, 2016

    @sandy081
    MemberAuthor

    Peng Lyu (@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?

  5. rebornix commented on Aug 16, 2016

    @rebornix
    Contributor

    Sandeep Somavarapu (@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.

  6. rebornix commented on Aug 16, 2016

    @rebornix
    Contributor

    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.

  7. sandy081 commented on Aug 16, 2016

    @sandy081
    MemberAuthor

    Peng Lyu (@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.

  8. rebornix commented on Aug 16, 2016

    @rebornix
    Contributor

    Sandeep Somavarapu (@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?

  9. added 2 commits that reference this issue on Aug 18, 2016
  10. sandy081 commented on Aug 19, 2016

    @sandy081
    MemberAuthor

    Peng Lyu (@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.

  11. rebornix commented on Aug 23, 2016

    @rebornix
    Contributor

    Sandeep Somavarapu (@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.

  12. sandy081 commented on Aug 23, 2016

    @sandy081
    MemberAuthor

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

  13. nschurmann commented on Jan 4, 2017

    @nschurmann

    Great, where do i write this config?

  14. rebornix commented on Jan 13, 2017

    @rebornix
    Contributor
  15. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

VIMapi

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions