microsoft/vscode

Add support for swipe gestures on Mac

brennanMKE opened this issue ยท 29 comments

  • VSCode Version:
    Latest
  • OS Version:
    OS X 10.11

Steps to Reproduce:

  1. Use VS Code's forward and back navigation hot keys
  2. Try to do the same by swiping left and right

On a Mac the Safari web browser can use the forward and back buttons to go back and forth with web pages. I do this with VS Code using hot keys when working with various files. I navigate forward by clicking through function and class names and and often want to go back. Swiping is the most natural gesture.

There was a request to add these gestures in Electron but the issue was closed. I feel it should be reopened.

nylas/nylas-mail#541

In that case, managing horizontal scroll might be a problem. Swipe gesture could be supported when Command or Control key is pressed perhaps?

If it's not supported by Electron then it won't be possible in VSCode.

This recently came available in Electron 0.37.4 but I am really wondering how this feature would work together with horizontal scrolling?

@bpasero Override when fn key is pressed maybe? ๐Ÿ˜„

I'd expect it to work like it does with Xcode and Safari. If it does not conform to the same behavior then usage won't fit in well with the other apps. As I use Safari and Xcode and come back to VS Code I naturally try to swipe back and forward between files but have to fall back to the hot keys instead of the gesture.

As for the concern for horizontal scrolling, it has not been an issue with Xcode where I use this gesture the most. Since most developers try to keep their code within a reasonable number of characters per line I do not expect scrolling left and right will be an issue.

coreh commented

The way this normally is implemented is:

// inside the swipe left start event handler
if (window.scrollX == 0) {
  // actually register swipe 
}

(And the same logic for the other direction.)

That way if the user can scroll left, they need to do so, remove their hands of the trackpad, then swipe again to trigger the navigation. (Really hard to activate by accident)

It's also important to check if this works as expected with natural scrolling disabled.

Visual/animated feedback might be a bit tricky, but I think a v1 without it would be mostly fine.

three finger swipe would also be great for forward/back navigation. on macOS this is one of the sub options of the trackpad gesture settings and avoids conflict with regular horizontal scroll in lots of apps. That's probably an event that comes through different to regular scroll.

Either way: +1 from me, this would be great, the more native gesture support the better.

Three finger swipe on the Mac will move between virtual windows or Full Screen apps. In System Preferences under Trackpad the More Gestures tab shows the various options which include the 2 and 3 finger swiping gestures.

Typically 2 fingers will scroll vertically or horizontally. If there is no more content for scrolling left or right then it would start pulling the previous or next document if there is one.

Below are GIF animations of the 2 and 3 finger gestures in System Preferences and what Xcode looks like when using the 2 finger swipe gestures left and right.

swipe gestures

xcode swiping

I have the finger count sub-option set up to be unambiguous between them and scrolling like so:
screen shot 2016-09-14 at 1 27 21 pm
Which causes the pages to change without the transition animation.
This solved a few poor performance and glitchy gesture collisions for me in the past. This is what makes me think the event may be different, but just throwing in my two cents.
Hope this helps.

I am really missing this feature today. I am using Xcode and VSCode a lot recently today and I forget which one I am using as I dig through a lot of code. I cannot simply swipe forward and back.

Same here. This would be a huge productivity boost for those that are used to the functionality in Xcode.

Yup, for those who come from Xcode know how much of a productivity boost it is to swipe between files. I use three fingers myself and constantly miss it in VSCode.

The PR that is now out there (#23663) makes this possible quite easily and it does not interfere with scrolling because it only supports the 3-finger swipe (left / right). And it only works for me with the following trackpad setting:

image

Is that what people would expect and use?

screen shot 2017-03-31 at 7 38 07 am

I'm using MBA which is without the Force Touch trackpad. I always enable three finger drag (through Accessibility settings) and use it for text selections. Xcode like swipe gestures would suit the best. Swipe to the previous screen/document with 2 finger scroll when the screen/document is at the edge. ๐Ÿ˜„

@bpasero I use 2 fingers to move back and forth in Xcode and Safari. I would not want to change the gesture just for VSCode. If the gesture can be picked up from the Mac environment that would likely be the best way to handle it. I don't know how much work is required to put native gesture recognition into an app built on Electron.

@brennanMKE @xeoneux Looks like we have different preferences then.

I personally prefer the instant swipe with three fingers instead of the slow "page moving off the stack" .
Working with Xcode daily, the latter tend to be buggy and slow vs just instant swipes.

The PR does the three finger instant swipe.

apr-06-2017 13-24-41

@seivan I would have really loved the instant swiping of pages had I not been using three fingers to select the text! ๐Ÿ™ˆ

vqhuy commented

Just one more feedback for @seivan and @bpasero: I also use 2 fingers to move back and forth in Xcode and Firefox, and I don't want to change the habit because of vscode.

@c633 No worries, it's off by default.

What are peoples feeling around swipe navigating in editor history within the document (provided you navigated around in the document enough) instead of navigating between used editors in MRU order? This was reported during testing via #25449

In other words, today:

  • navigate around in an editor (more than 10 lines)
  • swipe left/right
    => you navigate within the document

Alternative:

  • swipe
    => you navigate between the last used document, but never within
vqhuy commented

I would like to use swiping for Go Back/ Go Ahead.

@bpasero would love to have both the navigations. Here's what would be an ideal solution for me:

Default: Only navigate between last used documents, but never within.
Modifier: Only navigate within the current document, but never to last used.

Control ^ would be the perfect modifier on macOS ๐Ÿ˜ธ

Just curious, who else uses โ‡ช as โŒƒ key on their Macs?

@c633 is that how it works now or how the alternate solution would be?

Thinking more about it, I lean towards changing the swipe to work across documents, especially since that is what the macOS description tells what's happening:

image

I have pushed a change so that swiping will navigate across editors and never within editors. My feeling is that if we make this configurable, this should be done as part of the general support for customizing mouse behaviour: #3130

If you look at Safari and Chrome, the two finger swipe left or right moves through your history, not between pages/tabs. This makes the most sense given the default of macOS.

@bpasero that's amazing! ๐Ÿ˜ธ I'll create a new issue to track the custom mouse behaviour for this.

@bpasero

In other words, today:

navigate around in an editor (more than 10 lines)
swipe left/right
=> you navigate within the document

Is the behaviour I have in Xcode and I'd like that here as well.

But the Swiping is just an event. It's the "VSCode" actions that does the heavy lifting.

For now I've ended up with temporary solution using BetterTouchTool to map touchpad gesture into keyboard shortcut. Check screenshot for configuration. It's two finger swipes.
As a bonusit includes three-finger swipes for cycling between tabs. It's nice feature I saw on chromebooks and loved it now I've added this to all my aps with tabs support
monosnap 2017-07-23 15-35-31