microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
40.34k stars 3.59k forks source link

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

Open MiguelEste opened 9 months ago

MiguelEste commented 9 months ago

Reproducible in vscode.dev or in 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

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.

abdalla-rko commented 1 week ago

I've got the same issue. Any updates?