Is there a command to move the view up and down?


#1

Hello,
I have been looking around for a little while, but can’t find the answer, so perhaps someone here will be able to help me.

I am looking for a command that can move the editor view in Atom up and down without moving the cursor.

I am trying to make the switch from Sublime, so if it helps the setting I use in that is:
"command": "scroll_lines", "args": { "amount": 10.0 }

The behaviour in Sublime that I’m looking to replicate in Atom is that:

  • If no text is selected then the view will move up and down and the cursor will be moved with it before it goes out of view on the top or bottom
  • If text is selected then the view will move but the selections/cursors will not be moved at all

I found some packages that allow the cursor to jump multiple lines at once, but I would rather have the view move independently of the cursor.

Is this possible in Atom?


#2

It’s ok, I found out how to create my own commands and I’m happy using this:

atom.commands.add 'atom-text-editor',
  'user:scroll-up': (event) ->
    editor = @getModel()
    scrollTop = editor.getScrollTop()
    lineHeight = editor.getLineHeightInPixels()
    scrollTo = scrollTop - (lineHeight * 10)

    editor.setScrollTop(scrollTo)

atom.commands.add 'atom-text-editor',
  'user:scroll-down': (event) ->
    editor = @getModel()
    scrollTop = editor.getScrollTop()
    lineHeight = editor.getLineHeightInPixels()
    scrollTo = scrollTop + (lineHeight * 10)

    editor.setScrollTop(scrollTo)

#3

Works perfectly, thanks! Want to add some info:

  • code snippet should be placed in the init.coffee
  • then should add key bindings in the keymap.cson
  • then restart atom

#4

Or someone could make a package out of it to make it easy for people to install :wink: