Skip to content

Support stylus/pen text selection on Android tablets#320994

Open
DaniilBabanin wants to merge 1 commit into
microsoft:mainfrom
DaniilBabanin:android-tablet-pen-selection
Open

Support stylus/pen text selection on Android tablets#320994
DaniilBabanin wants to merge 1 commit into
microsoft:mainfrom
DaniilBabanin:android-tablet-pen-selection

Conversation

@DaniilBabanin

Copy link
Copy Markdown

This lets a stylus/pen drag select text in the editor on Android tablets, the same as it already does on iOS and Android phones. A finger drag still scrolls and the mouse is unchanged.

Problem

#198578 added the pen/stylus selection path (PointerEventHandler) for mobile devices, gated by:

const isPhone = platform.isIOS || (platform.isAndroid && platform.isMobile);

platform.isMobile looks for a Mobi token in the user agent, and Android tablets generally omit it. So on a tablet the editor falls back to TouchHandler, where pen input behaves like a finger: it can scroll but never select text.

Change

Drop the platform.isMobile requirement for Android, so any Android device with Pointer Events support gets PointerEventHandler. The iOS branch is untouched, and Android phones already satisfied the old condition, so behavior only changes for Android tablets.

Testing

This change was first made as a patch in code-server (coder/code-server#7841), where I built and tested it on a Samsung tablet with an S Pen in Chrome:

  • Pen drag across text selects it.
  • Finger drag scrolls.
  • Pen barrel button + tap opens the context menu.
  • Mouse selection and right-click are unchanged.

It is also reproducible in desktop Chrome with DevTools device mode set to an Android tablet user agent without a Mobi token. The code-server maintainers asked that the fix be submitted upstream rather than maintained as a patch, hence this PR.

platform.isMobile requires a Mobi token in the user agent, which Android
tablets usually omit, so they fell back to TouchHandler and a stylus
could only scroll. Widen the Android check so tablets get the pen-aware
PointerEventHandler too, matching what iOS already does.

Follow-up to microsoft#198578
Copilot AI review requested due to automatic review settings June 11, 2026 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adjusts device detection in the editor pointer handler to broaden when the PointerEventHandler path is used on Android.

Changes:

  • Treat all Android devices as “phone” for pointer handling, instead of only Android mobile.
  • Potentially alter the event-handling path selection when BrowserFeatures.pointerEvents is available.

Comment on lines +144 to 145
const isPhone = platform.isIOS || platform.isAndroid;
if (isPhone && BrowserFeatures.pointerEvents) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including Android tablets is the intent of this PR — on tablets the TouchEvent fallback means a stylus can only scroll, never select text (see the PR description). Two points on the suggested alternatives:

  • The condition is already gated by actual pointer capabilities: the handler is only chosen when BrowserFeatures.pointerEvents is true, otherwise the TouchEvent/mouse fallbacks apply as before.
  • There is precedent for tablets on this path: platform.isIOS already routes iPads through PointerEventHandler, where finger scrolling and pen selection coexist fine. This change just gives Android tablets the same treatment, and it behaves the same way in testing on a Samsung tablet with an S Pen (pen selects, finger scrolls, mouse unchanged — details in Support stylus/pen text selection on Android coder/code-server#7841).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants