Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[terminal] Cmd + click doesn't work on iPad (iOS 12) #6320

Closed
jankeromnes opened this issue Oct 3, 2019 · 8 comments · Fixed by #6875
Closed

[terminal] Cmd + click doesn't work on iPad (iOS 12) #6320

jankeromnes opened this issue Oct 3, 2019 · 8 comments · Fixed by #6875
Labels
ipad issues related to iPad

Comments

@jankeromnes
Copy link
Member

Description

There is currently no way to click on Terminal links on iPad.

The Cmd + click to follow link tooltip does show up, but pressing Cmd on my external bluetooth keyboard and tapping the link doesn't work.

Reproduction Steps

  1. Open Theia on an iPad (I tried iOS 12), in any browser (they're all Safari anyway)
  2. Run echo "https://theia-ide.org" in a Terminal
  3. Try to click the link. Also try pressing Cmd as indicated and click. It doesn't work.

OS and Theia version: master

Diagnostics:

The good news is that tapping on the link is detected, because this listener is being called:

protected isCommandPressed(event: MouseEvent): boolean {
return isOSX ? event.metaKey : event.ctrlKey;
}

The bad news is that isOSX ? event.metaKey : event.ctrlKey is always false on iPad.

In fact, I've tried to detect several different modifier keys, but pressing any of these on my iPad's external bluetooth keyboard is never detected by the event listener. I've tried:

  • event.altKey
  • event.metaKey
  • event.ctrlKey
  • event.shiftKey
  • event.getModifierState('Alt')
  • event.getModifierState('Control')
  • event.getModifierState('Shift')
  • event.getModifierState('CapsLock')
  • event.getModifierState('Fn')
  • event.getModifierState('Super')
  • event.getModifierState('Accel')

They're all false, always. And even on https://keycode.info/ it's quite hard to get the Cmd / Control / Alt / Shift keys of my iPad keyboard detected.

Maybe we should make Terminal links directly clickable on iPad? I think that would be a huge improvement over the current situation.

@jankeromnes
Copy link
Member Author

Part of #3557.

@akosyakov akosyakov added the ipad issues related to iPad label Oct 3, 2019
@jankeromnes
Copy link
Member Author

@akosyakov @vince-fugnitto @marcdumais-work Do you have any thoughts on making all Terminal links immediately clickable on touch devices?

I personally believe that accidental link clicks are less likely with touch-screens than on desktop, and having some way to follow links there would be great.

@marcdumais-work
Copy link
Contributor

Hi @jankeromnes ,

I personally believe that accidental link clicks are less likely with touch-screens than on desktop, and having some way to follow links there would be great.

Sounds reasonable.

Is an iPad detected as "OSX" in the code above? If so is there a way to distinguish from a Mac laptop? Would it be possible and worth the trouble to do this generally for other devices similar to an iPad, like Android tablets?

@vince-fugnitto
Copy link
Member

@akosyakov @vince-fugnitto @marcdumais-work Do you have any thoughts on making all Terminal links immediately clickable on touch devices?

It might be worthwhile to attempt to debug and see what is happening, and also try out to see what happens when listening to touchevents explicitly (reference).

@jankeromnes
Copy link
Member Author

Thanks a lot for your input, Marc and Vince!

Is an iPad detected as "OSX" in the code above? If so is there a way to distinguish from a Mac laptop? Would it be possible and worth the trouble to do this generally for other devices similar to an iPad, like Android tablets?

I'm not sure how to detect these different platforms yet, but I agree that the "always-clickable terminal link" special case should apply only to tablets like iPad and Android, and not to laptops (even if they have touchscreens).

It might be worthwhile to attempt to debug and see what is happening, and also try out to see what happens when listening to touchevents explicitly (reference).

I already did some debugging (see top comment), and what's happening is that the click is detected, but not the modifier keys, so we currently ignore the link "taps".

But you're right, maybe listening to touchevents can allow us to detect whether the link was "tapped" (with a finger on a touch screen) or actually "clicked" (with a mouse or touchpad). I think we'll want to enforce the modifier key only for mouse/pointer clicks, and make "taps" always open links regardless of keyboard state. I think this behavior even makes sense on laptops with touchscreens.

@marcdumais-work
Copy link
Contributor

But you're right, maybe listening to touchevents can allow us to detect whether the link was "tapped" (with a finger on a touch screen) or actually "clicked" (with a mouse or touchpad). I think we'll want to enforce the modifier key only for mouse/pointer clicks, and make "taps" always open links regardless of keyboard state. I think this behavior even makes sense on laptops with touchscreens.

👍

@jankeromnes
Copy link
Member Author

jankeromnes commented Jan 13, 2020

Update: I'm able to detect Terminal touchstart and touchend events by adding listeners next to the existing touchmove listener here:

document.addEventListener('touchmove', event => { event.preventDefault(); }, { passive: false });

Unfortunately, touchevents listeners only seem to work when attached to the document, not the Terminal element, and XtermJS can only tell us about the click events on its links, so some work needs to be done to correlate touch and click events.

Here is the handler that XtermJS calls when a Terminal link is clicked or tapped (even when the link won't open):

const wrappedHandler = (event: MouseEvent, match: string) => {
event.preventDefault();
if (this.isCommandPressed(event)) {
handler(event, match);
} else {
term.focus();
}
};

Maybe we can correlate event times / targets / coordinates in order to known when the click handler was triggered by a touch?

In my testing on iPad, here is the full sequence of events I see:

Time Event event.target event.pageX x Y
2020-01-13T11:32:32.818Z touchstart canvas.xterm-cursor-layer 160 x 493
2020-01-13T11:32:32.912Z touchend canvas.xterm-cursor-layer 160 x 493
2020-01-13T11:32:32.962Z willLinkActivate canvas.xterm-cursor-layer 160 x 493
2020-01-13T11:32:32.964Z click canvas.xterm-cursor-layer 160 x 493
2020-01-13T11:32:33.431Z tooltipCallback canvas.xterm-cursor-layer 160 x 493

(In this run, all coordinates are exactly the same, but I've seen many cases where the touch and click coordinates are off by one, so some fuzzy-matching may be necessary.)

@jankeromnes
Copy link
Member Author

Actually, with iOS 1.13, Cmd + click now works now on iPad if you have an external keyboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ipad issues related to iPad
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants