Repository navigation
Add on-demand on-screen keyboard for Monaco editor on touch devices - #8167
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 module (mobileOnDemandKeyboard.ts) which puts the editor in a read mode on touch devices by default, so taps don't summon the OS virtual keyboard. A double-tap inside the editor enters typing mode; tapping outside, or the browser reporting the keyboard dismissed, exits back to read mode. Fixes coder#8166
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.
Problem: hypersenstivie keyboard appearing after every screen interaction (Android)
I am an Android code-server user. I use my phone to read and edit files on my vps, code-server is my UI.
I ran into the problem of hypersensitive keyboard that pops up on any screentouch. It's annoying to me because i can't swipe to read text without having to close the keyboard after each swipe.
I built a patch to solve the problem for myself. Sharing it so that you can assess if it's valuable for the product.
Solution
[this pr attemts to fix the issue number 8166]
A standalone 292-line TypeScript module (zero dependencies) makes the on-screen keyboard on-demand: the editor starts in a read mode by default on touch devices, and the user opts into typing mode with a double-tap. It ships as a quilt patch under
patches/mobile-on-demand-keyboard.diff— matching the existing convention for every other code-server change against vendored vscode — which addsmobileOnDemandKeyboard.tsnext toworkbench.tsand wires its initializer into the workbench bootstrap.Monaco exposes two input shapes across versions — the legacy hidden
textarea.inputareaand the modern EditContext-APIdiv.native-edit-context— and both get the same treatment.The module keeps one piece of user-facing state,
typingMode(plus small closure vars for double-tap and viewport-resize detection), and installs three cooperating suppression layers so that whichever path Monaco (or the browser) uses to land focus on an input, that focus either doesn't take or lands without a keyboard:.focus()method override onHTMLTextAreaElement.prototypeandHTMLElement.prototype. Monaco callsel.focus()directly in a lot of places; the override silently drops those calls when they target a Monaco input and typing mode is off. Installed synchronously at module load, before the workbench boots.focusinblur guard. If a focus does slip past the method override (e.g. via a browser-level path likeautofocus), the guard blurs the Monaco input the same tick. Second line of defense.inputmode="none"stamping. The OS honorsinputmode="none"on a focused input to suppress the virtual keyboard entirely. The module monkey-patchesElement.prototype.setAttribute,.setAttributeNSand theclassNamesetter so the attribute is set in the same synchronous block Monaco adds itsclass="inputarea"in — before Monaco's next line (thefocus()call) runs. AMutationObserverstays in place as a safety net for paths the setter hooks don't cover.On top of that, the module watches two signals to go back to read mode automatically:
.monaco-editorwhile in typing mode toggles typing mode off (and blurs the active element, which dismisses the keyboard).visualViewportresize with a large height growth indicates the OS keyboard just closed (user hit the down-arrow / back gesture). Typing mode flips off so the next editor tap doesn't just reopen it.A double-tap inside the editor toggles typing mode. The threshold is 350ms between taps, 30px of drift.
On desktop
typingModeinitializes totrue(IS_TOUCHis false), so every suppression branch — the.focus()override, the focusin blur guard, and theinputmode="none"stamp — short-circuits on its!typingModecheck. The listeners and prototype wrappers are still installed, but their guard condition is never satisfied. On touch devices the module reacts to taps everywhere on the page: inside.monaco-editora double-tap toggles typing mode, outside it a single tap in typing mode exits back to read mode. It also reacts to Monaco's two input element classes being set on or added to any element in the DOM, and tovisualViewport.resizeevents.Testing
Playwright e2e.
test/e2e/mobileOnDemandKeyboard.test.tsenables touch per-test viatest.use({ hasTouch: true, ... })and asserts the module's observable DOM effects:inputmode="none"is stamped on the Monaco textarea.el.focus()on the Monaco textarea does not take focus in read mode.inputmode(typing mode on).inputmode="none"(typing mode off).Playwright has no way to observe "the OS keyboard opened" directly, so the test targets the observable preconditions for suppression rather than the OS behavior itself.
On-device. An earlier JS prototype of this module has been my daily driver on a Pixel 6 over Tailscale for a few days alongside the pinch-zoom module. The TypeScript port submitted in this PR was compiled from the exact module in the patch and deployed to the same device today, and behaves identically: scrolling and caret-positioning work without the keyboard appearing, a double-tap reliably opens the keyboard, and the OS down-arrow / tap-outside paths both return to read mode.
Commits are signed.