microsoft / microsoft/monaco-editor
[Bug] Keyevents fired twice on new editor after disposing diff editor on same domElement (parent)
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 = `function hello() {
alert('Hello world!');
}`;
const myDiffEditor = monaco.editor.createDiffEditor(document.getElementById("container"), {
enableSplitViewResizing: true, renderSideBySide: true
});
myDiffEditor.setModel({
original: monaco.editor.createModel(value, "javascript"),
modified: monaco.editor.createModel(value.replace("world", "darkness"), "javascript"),
});
setTimeout(() => {
myDiffEditor.dispose();
monaco.editor.create(document.getElementById("container"), {
value, language: "javascript", automaticLayout: true
});
}, 2000);
Reproduction Steps
- Wait until the diff editor is disposed and replaced by a normal editor (2 seconds)
- Navigate the code in the editor with the arrowkeys
Actual (Problematic) Behavior
Notice how the cursor will move 2 spaces, instead of 1.
Expected Behavior
the cursor should only move 1 space per keypress, not 2
Additional Context
Broken since 0.44.0, works as expected on V0.43.0.
Same problem with pressing backspace to remove code and using undo redo. Both will be fired twice, instead of once.
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 with the linked Monaco Editor Playground reproduction and trace the diff editor disposal followed by creating a normal editor on the same container. Verify arrow keys, backspace, undo, and redo fire once after replacement, matching the behavior from version 0.43.0 rather than 0.44.0 and later.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100