microsoft / microsoft/monaco-editor

[Bug] Typing with backward (RTL) selection fails when editContext: false

Open
#5,207 7 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.55.1#XQAAAAJyAQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscwzfLcO_1uhs0-3YGTBOsVJ4S4FwfCDQb5-2uUHXTVAefbVSd9IzaZ_vv9VR9KugsKimARHSWlrTPOQHROITHxmAetfeRrm3VHdSe7_Etv6WpgzlH4vE8EOEDMNvLzPHayHVIURO2M6qOjjOCBmDnp9jHpzW-FcCFVbyRo9s1yu9JcALg0-q4mS26nJaSDhuVeFsYGKO0Io6JDuxXgCYOTLCbhVeWicHHKc38WIrk2e5pQg4dDatl-PvOuuXTMg3Zd8-S0Rnc_6N7EkhE4UW13jxSA6H8c1HzrreiAjNnK1_BnKLlTHPFla17_8NmDyg

Monaco Editor Playground Code
const value = /* set from `myEditor.getModel()`: */ `function hello() {
	alert('Hello world!');
}`;

const myEditor = monaco.editor.create(document.getElementById("container"), {
	value,
	language: "javascript",
	automaticLayout: true,
	editContext: false // this causes the bug
});
Reproduction Steps
  1. Set editContext: false in editor config
  2. Select text in editor from right to left
  3. Type a single character to replace the selected text
  4. Observe: the character does not replace the text
Actual (Problematic) Behavior

RTL selections are not immediately replaced by a valid character, the first keypress is ignored.

Expected Behavior

The text replacement should occur immediately, after the first keypress, regardless of the selection direction.

Additional Context

editContext: false is a necessary workaround for #5081. Users who need that fix now hit this RTL bug.

Workaround

Intercept keydown and use editor.trigger() for RTL selections

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Monaco Editor Playground and reproduce the issue using the provided editor configuration with editContext: false. Compare right-to-left and left-to-right selections, then trace the editor's selection and keypress handling for this setting. Done means the first typed character immediately replaces the selected text in both directions without requiring the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.