Repository navigation
Add mobile pinch-to-zoom and drag-to-pan - #8161
Open
elias-coderunner wants to merge 1 commit into
Open
elias-coderunner wants to merge 1 commit into
elias-coderunner wants to merge 1 commit into
Conversation
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.
too tight for a 6" screen held at reading distance. I end up squinting
or giving up and switching to a laptop.
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.tsnext toworkbench.ts, wires its initializer into the workbench bootstrap, andflips the viewport meta tag in
workbench.html/workbench-dev.html.The zoom is implemented via CSS
zoomon the element — notfont-size, not CSStransform: scale. CSSzoomis the one propertythat scales every dimension Monaco reads (line heights, gutter, minimap,
scrollbar track) in lock-step, so the canvas stays internally consistent
at any zoom level.
.monaco-editorsetsstyle.zoomon it. Range clamped to 1x–3x. Text, gutter, minimap andscrollbars scale together, no overlap or overdraw.
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.
zoom > 1), asingle-finger drag past an 8px threshold translates the editor via
transform: translate(), clamped to the content's own overflow box sothe 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.
zoomandtransformstyles and dispatches aresizeevent so Monacore-measures itself and the layout is bit-identical to pre-interaction.
Important because CSS
zoomdoesn't fire Monaco's ownResizeObserver, so without the nudge the chrome stays positionedfor the pre-reset layout until the next real resize.
user-scalable=no, maximum-scale=1.0touser-scalable=yes, maximum-scale=3.0in bothworkbench.htmlandworkbench-dev.html. Without this the browser swallows two-fingergestures before they ever reach the handler. The meta tag's source
actually lives in
microsoft/vscode; the quilt patch here flips thevendored copy, which is how every other
patches/*.difftouchesvscode 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.tsdrives a realChromium 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-editorand.explorer-folders-viewinline styles rather thanpoking any internals. Four scenarios:
style.zoomtoward 2x.zoomandtransform.translate().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
viewport meta ceiling, but someone on a larger tablet might
reasonably want 2x or 4x. Is
MAX_CANVAS_ZOOMworth exposing as acode-server setting, or is YAGNI the right call until someone asks?
.explorer-folders-view, .explorer-viewletto cover both thecurrent 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