microsoft / microsoft/monaco-editor

[Bug] Keyevents fired twice on new editor after disposing diff editor on same domElement (parent)

Open
#4,370 6 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug confirmed
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.45.0#XQAAAAJ-AgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw18iRu_1uhs0-3YGTBOs7toYAWtw3GzBo6G4BoZElnX11UnxON4zzkI3Krpl1C4v34gxEg92LSdufAq7cOoiHc0GRDIO5eEMcuRaeheKEdagEUzhL2mhCgZIUYxBY1DQ3rbONSCYu3xI1_XqxgKCoCCBsSsfVgV6hhOydyESCyDVsgD9ISDzx_VqryiinnrEy-QeATWIJxemgnRXbVj7lqcGuTEBuHUA56rEVaEC4HpRKbP1ie77cpuljybOEMl2raIwFJuWOPpqZmdokj9b_3eOH7RCMl6KuJq70gW36fFFrSpHLXSrCCtvOqn6VQnUKtP-S2bGQwCZd_2FZGFgyEjh1uuKsYStKKYqfYdBxDuR1CR_5ljRfKSvh68KmwCKntZ6MLv6njyskCY4kUC7TdnsnieXyb1wRQGrhEf8cjO8A

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.