Skip to content

Add mobile pinch-to-zoom and drag-to-pan - #8161

Open
elias-coderunner wants to merge 1 commit into
coder:mainfrom
elias-coderunner:feature/mobile-pinch-zoom
Open

elias-coderunner wants to merge 1 commit into
coder:mainfrom
elias-coderunner:feature/mobile-pinch-zoom

Conversation

@elias-coderunner

Copy link
Copy Markdown

The problem (as a code-server user on Android)

I use code-server on my Pixel 6 over Tailscale as a real editor — not a
demo. Three things stop that from working:

  1. I can't place the cursor where I want it. The default editor font
    is tuned for a desktop pointer. On a phone, my fingertip covers four
    or five lines of code at once, so tapping to position the caret is a
    coin flip between the line I wanted and the two above it.
  2. I can't read code comfortably. Characters are too small and lines
    too tight for a 6" screen held at reading distance. I end up squinting
    or giving up and switching to a laptop.
  3. I can't enlarge anything. The viewport meta tag code-server ships
    with disables browser pinch-zoom, and the editor itself exposes no
    mobile zoom UI. So the two normal escape hatches — OS pinch and
    in-app zoom — are both closed.

The net effect: code-server on a phone is viewable but not usable. This
PR makes it usable.

Fixes #8160

Solution

A standalone ~230-line TypeScript module (zero dependencies) adds
per-element pinch-to-zoom to the Monaco editor canvas and the file
explorer, and single-finger drag-to-pan to the editor once it's zoomed
in. It ships as a quilt patch under patches/mobile-pinch-zoom.diff —
matching the existing convention for every other code-server change
against vendored vscode — which adds mobilePinchZoom.ts next to
workbench.ts, wires its initializer into the workbench bootstrap, and
flips the viewport meta tag in workbench.html / workbench-dev.html.

The zoom is implemented via CSS zoom on the element — not
font-size, not CSS transform: scale. CSS zoom is the one property
that scales every dimension Monaco reads (line heights, gutter, minimap,
scrollbar track) in lock-step, so the canvas stays internally consistent
at any zoom level.

  • Editor pinch: two-finger pinch inside .monaco-editor sets
    style.zoom on it. Range clamped to 1x–3x. Text, gutter, minimap and
    scrollbars scale together, no overlap or overdraw.
  • Explorer pinch: two-finger pinch inside the file explorer scales
    the explorer independently via the same mechanism — so you can enlarge
    the file tree to make targets tappable without enlarging the code, or
    vice versa.
  • Drag-to-pan: once the editor is zoomed in (zoom > 1), a
    single-finger drag past an 8px threshold translates the editor via
    transform: translate(), clamped to the content's own overflow box so
    the user can never drag past the right scrollbar or above the top
    line. Below the 8px threshold the gesture falls through to Monaco so
    tap-to-position-cursor still works unchanged.
  • Pinch back out to 1x: strips both the inline zoom and
    transform styles and dispatches a resize event so Monaco
    re-measures itself and the layout is bit-identical to pre-interaction.
    Important because CSS zoom doesn't fire Monaco's own
    ResizeObserver, so without the nudge the chrome stays positioned
    for the pre-reset layout until the next real resize.
  • Viewport meta tag — one-line change from
    user-scalable=no, maximum-scale=1.0 to
    user-scalable=yes, maximum-scale=3.0 in both workbench.html and
    workbench-dev.html. Without this the browser swallows two-finger
    gestures before they ever reach the handler. The meta tag's source
    actually lives in microsoft/vscode; the quilt patch here flips the
    vendored copy, which is how every other patches/*.diff touches
    vscode files today.

The behavior is purely additive: on desktop (no touch events fired) the
module never activates, and on touch devices it only activates inside
the two targeted selectors. Nothing outside the editor canvas and
explorer is affected.

Testing

Playwright e2e. test/e2e/mobilePinchZoom.test.ts drives a real
Chromium with touch enabled, injects two-finger pinches through the
Chrome DevTools Protocol (Playwright's public touchscreen API is
single-touch only), and asserts the observable effects on
.monaco-editor and .explorer-folders-view inline styles rather than
poking any internals. Four scenarios:

  • Pinch-out on the editor raises style.zoom toward 2x.
  • Pinch back to 1x strips both inline zoom and transform.
  • One-finger drag on a zoomed editor produces a non-zero translate().
  • Pinching the explorer scales it independently of the editor.

On-device. I've also been using the build on my own Pixel 6 over
Tailscale as my daily driver for a few days — pinch, pan, tap-to-cursor,
pinch-back-out, re-pinch, and interaction with the explorer and the
peek-definition inline editor all feel right. No stuck transforms, no
overlapping lines, no cursor drift.

Commits are signed.

Open questions for maintainers

  1. Max-zoom as a config option. I've hard-coded 3x to match the
    viewport meta ceiling, but someone on a larger tablet might
    reasonably want 2x or 4x. Is MAX_CANVAS_ZOOM worth exposing as a
    code-server setting, or is YAGNI the right call until someone asks?
  2. Explorer selector robustness. I match
    .explorer-folders-view, .explorer-viewlet to cover both the
    current and slightly older DOM shapes I saw while testing. If
    there's a more canonical selector the project uses elsewhere, I'd
    prefer that.

Thanks for reading — and for maintaining code-server. This project is
the only reason the Android side of my workflow exists at all.

🤖 Generated with Claude Code

Adds a quilt patch that ships a per-element pinch-to-zoom and drag-to-pan
module for the Monaco editor and file explorer, so code-server is usable
on touch devices without external zoom extensions. Also flips the
vendored vscode viewport meta tag to allow browser gestures through.

Fixes coder#8160

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@elias-coderunner
elias-coderunner requested a review from a team as a code owner November 30, 2026 20:32

This branch has not been deployed

No deployments
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.

Pinch-to-zoom doesn't work on mobile; editor text is too small to read or edit

1 participant