[Feature Request] Add Native Touch-Based Text Selection Support for Mobile Devices
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, typescript
- Domain
- frontend, mobile-dev
Research direction
Start by reviewing the editor pointer and selection handling entry points and the public APIs cited in the issue: getTargetAtClientPoint, setSelection, and executeEdits. The issue describes desired mobile interactions but does not identify files, tests, or a settled design; first determine how touch input and native selection currently interact. Done means providing a supported touch selection experience or API that works in embedded mobile browsers while preserving normal editing behavior.
Written by the indexing model from the issue text.
Description
Context
- This issue is not a bug report. (please use a different template for reporting a bug)
- This issue is not a duplicate of an existing issue. (please use the search to find existing issues)
Description
Context
Monaco Editor is difficult to use for text selection on mobile devices, particularly in Android WebView and other touch-based environments.
On desktop, users can select text by clicking and dragging with a mouse. However, on mobile devices, the standard touch-based text selection experience, including draggable selection handles, is not consistently available.
This makes common editing operations, such as deleting a specific block of text, difficult to perform on mobile devices.
Feature Request
I would like to request built-in touch-based text selection support for mobile devices.
Ideally, Monaco Editor would support native-style text selection handles that allow users to adjust the beginning and end of a selection by dragging them.
Alternatively, a built-in tap-to-select mode would also be very useful. For example:
- Enable selection mode through a toolbar button or API.
- Tap the desired starting position.
- Tap the desired ending position.
- Monaco selects the text between the two positions.
- Perform an editing operation, such as deleting the selected text.
- Exit selection mode and return to normal editing.
This interaction would be especially useful in mobile applications that embed Monaco Editor inside an Android WebView or another embedded browser.
Current Workaround
I have implemented a temporary two-point selection and deletion mechanism in my application using Monaco's public APIs.
The workflow is:
Enable two-point selection → Tap point A → Tap point B → Press Backspace to delete the selected text → Disable selection mode.
The implementation uses:
editor.getDomNode()to attach apointeruplistener.editor.getTargetAtClientPoint()to map touch coordinates to Monaco model positions.monaco.Selectionandeditor.setSelection()to select the text between the two points.editor.executeEdits()to delete the selected range.- A capturing-phase
keydownlistener to intercept Backspace before Monaco's default keyboard handling.
Here is a simplified example of the core selection logic:
let selectionStart = null;
const editorDom = editor.getDomNode();
editorDom.addEventListener('pointerup', (event) => {
if (event.pointerType !== 'touch' &&
event.pointerType !== 'mouse') {
return;
}
const target = editor.getTargetAtClientPoint(
event.clientX,
event.clientY
);
const position = target?.position;
if (!position) {
return;
}
if (!selectionStart) {
selectionStart = position;
return;
}
const selection = new monaco.Selection(
selectionStart.lineNumber,
selectionStart.column,
position.lineNumber,
position.column
);
// Defer selection until the current pointer event has finished.
setTimeout(() => {
editor.setSelection(selection);
}, 0);
selectionStart = null;
}, { passive: true });
window.addEventListener('keydown', (event) => {
if (event.key !== 'Backspace') {
return;
}
const selection = editor.getSelection();
if (!selection || selection.isEmpty()) {
return;
}
event.preventDefault();
event.stopPropagation();
const model = editor.getModel();
if (!model) {
return;
}
editor.executeEdits('touch-selection-delete', [{
range: selection,
text: ''
}]);
}, true);
This is only a simplified proof of concept. A production implementation would also need explicit selection-mode state, cleanup when the mode is disabled, handling for reversed selections, and safeguards to avoid intercepting Backspace during normal editing.
Expected Benefits
- Makes text selection and editing more practical on mobile devices.
- Improves usability in Android WebView and other embedded browser environments.
- Provides a consistent interaction model across touch-based devices.
- Reduces the need for applications to implement custom selection logic and keyboard-event handling.
I understand that Monaco Editor is primarily designed for desktop use, and I appreciate that mobile interaction may require additional design considerations. However, even an optional, API-controlled touch selection mode would be a valuable improvement.
Would the team consider adding native touch selection support or providing a supported API for implementing tap-to-select interactions?
Thank you for your work on Monaco Editor.
Monaco Editor Playground Link
No response
Monaco Editor Playground Code
- Dominant language
- JavaScript
- Stars
- 47k
- Forks
- 4.2k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 13
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/monaco-editor
-
Difficulty 1/5 1-3 hours Newbie friendliness 65/100
microsoft/monaco-editor#5626 ·
Maintainers usually reply within 1 day
-
[Bug] package.json `"typings"` points to a file which does not exist in the npm packagePossibly taken @whoalin1 claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/monaco-editor#5615 ·
Maintainers usually reply within 1 day
-
[Bug] C# scientific-notation literals without a decimal point are split into identifiersPossibly taken @Janani-bn claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
microsoft/monaco-editor#5583 ·
Maintainers usually reply within 1 day
-
[Bug] Rust scientific-notation literals without an exponent sign are split into identifiersPossibly taken @Janani-bn claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/monaco-editor#5582 ·
Maintainers usually reply within 1 day
-
[Bug] Go numeric literals with underscore separators are split into identifiersMay be free again @aaronanish-t claimed this 25 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
microsoft/monaco-editor#5577 · 1 comment ·
Maintainers usually reply within 1 day
All issues in microsoft/monaco-editor
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quasarframework/quasar#18614 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug/1-unconfirmed kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
521xueweihan/HelloGitHub#4714 ·
-
01 type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day