microsoft/vscode

Multiple cursors binding

berdario opened this issue ยท 18 comments

On most Linux desktops alt+click will allow you drag a window by clicking anywhere over it. This conflicts with the multiple cursors binding.

It's still possible to obtain multiple cursors with commands like insertCursorAbove or insertCursorAtEndOfEachLineSelected, but this affects multiple people, and it's already covered in some articles with a workaround (which I'm copying here for Gnome based systems: gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>" change <Super> with your preferred key )

It's also acknowledged in VScode's documentation that this shortcut might conflict even on Windows or Macosx...

Note: Your graphics card provider might overwrite these default shortcuts.

So, fixing this for Linux users might also be useful elsewhere. For comparison, the Atom editor uses ctrl+click instead of alt+click for this shortcut.

Rather than changing the default, making it customizable would already be a welcome improvement, but afaik unfortunately there's no way to change it. These are a couple of related default keybindings:

{ "key": "ctrl+shift+up",         "command": "editor.action.insertCursorAbove",
                                 "when": "editorTextFocus" },
{ "key": "shift+alt+up",          "command": "editor.action.insertCursorAbove",
                                 "when": "editorTextFocus" }

But since I cannot find any editor.action.insertCursor command, it seems that this option is lacking.

This is fairly easy to change to ctrl in MouseHandler._updateMouse, however then it conflicts with ctrl+click to open a link. Atom doesn't seem to support ctrl+click to open links so there is no conflict there. @berdario ctrl+alt and alt+shift seem to be free, just adding another modifier may be better than changing both add a selection and open a link for Linux.

I don't think we currently allow customization of mouse shortcuts, only pure keyboard ones. Created #3130 for this.

I'm leaning towards alt+shift so it matches the default for add selection up/down.

@alexandrudima What do you think we should make the alt+click shortcut on Linux? alt+click can't be used because it conflicts on the OS-level. I was thinking alt+shift+click previously but it seems that's used to expand the selection of the last selection without touching the others.

Atom uses ctrl+click, but that would conflict with link clicking in VSCode. Would adding ctrl to the shortcuts such that alt+ctrl+click adds a cursor and alt+ctrl+shift+click expands the last cursor selection work?

@Tyriar I did some testing, ctrl+alt will work, it does not trigger the same window move behavior in gnome that alt+click does, shift+alt does still trigger the move mode.

Whichever combination you end up going with can we please get those configurable in the keybindings.json file?

The mouse gesture dispatching doesn't go through the keybindings rules, but I agree this should be configurable somehow.

Here is where the built-in editor mouse dispatching happens: https://github.com/Microsoft/vscode/blob/c4b514244e2651117b9990295730265f5b902436/src/vs/editor/browser/view/viewController.ts#L66

There are other places in code, such as the link handler that handle Ctrl+Click programmatically.

It would be a bit tricky, but doable I think, to have the IMouseDispatchData go through a rule engine that determines what command to invoke on the editor.

We can easily change the code to do something different in Linux, but implementing a rule engine (that would ultimately solve all problems since it would allow configuration) would be a bit more complicated.

@alexandrudima I feel the rule engine is worth it, fixing the conflict with alt+Click is really a short sighed solution. As I'm sure you're aware linux can be quite varied (read: fragmented) sometimes. Fixing the conflict will solve issues for people running Gnome, but it may end up conflicting with KDE, or with XFCE, or with whatever other variant someone has decided to run. I think it's best to go the rule engine route, even if it takes a little longer.

Also, there's no telling what Apple or even Microsoft may do with mouse/touch gestures in the future, it's an evolving UX space, I think it would be better than playing cat and mouse with hardcoded gesture bindings.

@Reanmachine totally agree, the customizable mouse shortcuts is captured in this issue #3130.

Any updates on this guys?

This is blocked on #3130 imo

This fixed my xenial.
gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "<Super>"

Fixed via #27193

There is now a configuration option editor.multicursorModifier that can be set to ctrl or alt on Linux. The go to definition and open link modifiers will adjust accordingly.

Further changes were done in #27680 -- the setting is now editor.multiCursorModifier which can be ctrlCmd or alt

Marking as verified because this was on the test plan.

Is there no way to specify a completely custom modifier? I'm too used to using ctrl/cmd for the goto to switch, but at the same time being able to set multiple cursors anywhere is too big for me to lose. I'd ideally like to set it to a combination of keys, such as ctrl+alt.

@Ratismal Unfortunately not at this time. We have an item #3130 that tracks that. It is, however, a bit tricky to express all the various imperative code we use today for mouse operations in a declarative format that is also straight-forward enough that end-users could edit.

Fair enough @alexandrudima. I just unbound the alt+click shortcut from my xfce settings, since I never used it anyways and it was actually interfering with other programs.

Thanks for the speedy response!

@Ratismal Just use the editor config that alex noted.
"editor.multiCursorModifier": "ctrlCmd",
in your User Settings will allow you to Ctrl + Click for multi cursor. It works great!

@luncht1me Yes, but as mentioned I'd lose the ability to use the goto feature. It's far better to just unbind the global alt+click hotkey so that my workspace on linux and windows is the same.