microsoft / microsoft/monaco-editor
[Bug] UTF-8 unicode characters break editor.setSelection()
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?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Monaco Editor Playground Code
const value = /* set from `myEditor.getModel()`: */ `var 💣 2`;
// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
value,
automaticLayout: true,
});
myEditor.setSelection({
endColumn: 6,
endLineNumber: 1,
startColumn: 5,
startLineNumber: 1
})
console.log("DEBUG: " + myEditor.getSelection())
Reproduction Steps
After code executes, watch the editor current selection as well as the console log.
Actual (Problematic) Behavior
The unicode character doesn't get selected, also, the editor.getSelection() value doesn't match the one I put in in the previous editor.setSelection() call.
Expected Behavior
I expect to see the bomb emoji as selected, also notice what value gets retrieved when i call editor.getSelection() afterward (i logged the value in the console).
Additional Context
If you change the setSelection values to 1:1 -> 1:2 the selection works, but if you put 1:7 -> 1:8 it selects the wrong character (supposed to be the number)
Contributor 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.
Research direction
Start by running the linked Monaco Editor Playground example with var 💣 2 and compare setSelection() with the subsequent getSelection() result. Trace the editor selection and column-handling entry points involved; done means the emoji is selected for columns 5–6 and the returned selection matches the requested range.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100