Sublime Forum

Is there any way to ignore whether the Command key is pressed when scrolling?

#1

When I press the command key and try to scroll in Sublime Text, it seems as though I can’t scroll anymore. I feel like ⌘+scrolling is supposed to increase/decrease the font size, but I don’t want that and if this is a feature I probably turned it off as it doesn’t happen when I ⌘+scroll. However, I can’t scroll at all when I press the ⌘ and try to scroll, which is a bit of an inconvenient. An example of where this might be a liability is when I try to put down multiple cursors – likely in different parts of my document. I need to ⌘+click to do this, but when I scroll, because of this behavior, I need to undress ⌘ whenever scrolling to another location (and then press it again when putting down another cursor).

I thought there would be a keybinding setting to modify this, but if there is, I can’t find it. I also tried googling, but I got results related to scrolling with the keyboard, unfortunately.

0 Likes

#2

Open your ST console ctrl+` and paste:

window.run_command("edit_settings", { "base_file": "${packages}/Default/Default ($platform).sublime-mousemap", "default": "[\n\t$0\n]\n" })

Then edit the ctrl+scroll_up/scroll_down mousebinding.

3 Likes

#3

Wow, those are some nice settings. However, it doesn’t look like there are any scroll keybindings in that file, if I’m not mistaken.

0 Likes

#4

Sorry I didn’t look at the OSX mousebindings. This doesn’t seem to have scroll bindings :confused:
In windows you have those:

    // Change font size with ctrl+scroll wheel
    { "button": "scroll_down", "modifiers": ["ctrl"], "command": "decrease_font_size" },
    { "button": "scroll_up", "modifiers": ["ctrl"], "command": "increase_font_size" },

and can replace them e.g. by this:

    {
        "button": "scroll_down", "modifiers": ["ctrl"],
        "command": "scroll_lines", "args": {"amount": -4.0} // <- number of lines
    },
    {
        "button": "scroll_up", "modifiers": ["ctrl"],
        "command": "scroll_lines", "args": {"amount": 4.0}
    },

Not sure about OSX, but you can also try to add that mousebinding.

0 Likes

#5

Yeah, thanks, I just tried it from this post. It seems as though it doesn’t work with the physical trackpad, but it does work with an external mouse. That’s great in some cases, but not what I need. :smiley:

I wonder if Sublime Text has any way of modifying the Mac trackpad scroll behavior…

Also, although I can modify the external mouse scrolling behavior, I just tried this to achieve what I wanted (i.e. normal scrolling when ⌘+scrolling), but it didn’t work:

{ "button": "scroll_down", "modifiers": ["super"], "command": "scroll_up"},
{ "button": "scroll_up", "modifiers": ["super"], "command": "scroll_down"},

It looks like I can’t scroll at all with this in my file, which is the same behavior as I get as when I didn’t edit the file. However, doing something like this works:

{ "button": "scroll_down", "modifiers": ["super"], "command": "move", "args": { "by": "pages", "forward": true } },
{ "button": "scroll_up", "modifiers": ["super"], "command": "move", "args": { "by": "pages", "forward": false } },

This causes ⌘+scrolling to achieve fast scrolling, and I got this from the link I at the beginning of this post. I’m not sure what’s wrong with the syntax above. It probably is something trivial.

0 Likes

#6

Also, I did try your command, r-stein, but that seems to “cursor scroll” the document, which isn’t what I want. I want normal scrolling all the time, even when pressing command (just like the way you can scroll normally when pressing shift). I might sound a bit picky, but I just want the scrolling to feel more natural :slight_smile:.

Also, if ⌘ has the ability to stop you from scrolling in a document on the Mac, I feel as though there must be some way to counter this behavior by changing Sublime Text’s settings. Hmm…

0 Likes

#7

Oh I see that the caret stays inside the viewport, which is (in this scenario) obviously not desired. I don’t know if there is a built-in command to do it better otherwise one may just write a command to change the viewport, but not the caret.

0 Likes

#8

Just to reinvent the wheel: Select Tools > Developer > New Plugin… and paste this:

import sublime_plugin


class MyScrollCommand(sublime_plugin.TextCommand):
    def run(self, edit, amount, animate=True):
        view = self.view
        position = view.viewport_position()
        new_position = (position[0], position[1] - view.line_height() * amount)
        view.set_viewport_position(new_position, animate)

Afterward change your mousebindings to (adapt amount and animate as you wish):

    {
        "button": "scroll_down", "modifiers": ["ctrl"],
        "command": "my_scroll", "args": {"amount": -4.0, "animate": true}
    },
    {
        "button": "scroll_up", "modifiers": ["ctrl"],
        "command": "my_scroll", "args": {"amount": 4.0, "animate": true}
    },
1 Like

#9

Oh, wow, that’s actually quite amazing. It’s a pity that I hardly use an external mouse, because I have no idea how to get it to work with the trackpad. Nevertheless, I could use this to fast scroll in some other situations. Thanks!

Oh, and just to add, you pretty much solved this issue – it’s just due to some unforeseen problems it doesn’t work with the trackpad!

0 Likes

#10

By the way, @kingkeith , would you have any idea about this trackpad scrolling?

0 Likes

#11

no idea - have you tried executing sublime.log_commands(True) in the ST console and seeing if anything is triggered when using the trackpad to scroll?

0 Likes

#12

Great idea, but it didn’t work. Nothing comes up if I shift, command, alt, control, or function scroll with the trackpad or the external mouse.

However, normal scrolling doesn’t show anything either.

When I command or alt scroll with the trackpad, no scrolling occurs.

However, when I command scroll with my external mouse with the my_scroll command that r-stein showed me above, it does get shown.

So in conclusion it’s probably reasonable to assume that this command doesn’t show anything that occurs in terms of scrolling, unless a custom command is set to the scrolling option.

0 Likes