microsoft / monaco-editor

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

[Bug] Reusing the same container for diff editor and normal editor doubles some key events #4408

Open ckorherr opened 7 months ago

ckorherr commented 7 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.46.0#XQAAAALqAQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw0NV5ZhsAFQjfi1GSTeRDChAtr8RC8jhkfedYn4TxJcJIcii5J3w75DBaWbOhZVfaDoM0qNlMfjIIi_pOZYLb_yX2VN-mxu-31EI6AsKubDrHeOn3fZYRpWi1KUxh2o8VKGI7LMXVJRxHEnwngeYDTGHn_MvQm7gI3tM3v7q7odZIyj3tkPXGd6ood-qQEq5QZc9htrRKIl5cTTe9gUxIgdQlJLYIe_KvVnHMehoX20vMBOgD786Rg-CNED_yWwL2ZZqNvwL3d88f_-ZCt2A

Monaco Editor Playground Code

const originalModel = monaco.editor.createModel(
    /* set from `originalModel`: */ `hello world`,
    "text/plain"
);
const modifiedModel = monaco.editor.createModel(
    /* set from `modifiedModel`: */ `Hello World!`,
    "text/plain"
);

monaco.editor.createDiffEditor(document.getElementById("container")).dispose();

monaco.editor.create(document.getElementById("container"), {
    model: modifiedModel,
    language: "javascript",
});

Reproduction Steps

Run the code and use the left right keys inside the editor.

Actual (Problematic) Behavior

Cursor jumps 2 characters

Expected Behavior

Cursor jumps 1 character

Additional Context

Doing the same with two containers works. Backspace is also deleting two characters.

Reusing the container more than ones increases the events up to 3 times.

ckorherr commented 6 months ago

I think disposing a diff editor is not working, following is still returning the instance after disposing of it.

console.log(monaco.editor.getDiffEditors().length)

https://microsoft.github.io/monaco-editor/playground.html?source=v0.47.0#XQAAAAJWAgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw1uK2RgmSatbNyrNa50VLHWwDOn0YI7IfU0xJ0CGYU1vRtgnKPmZzQcQ1IYSLB-5f-1dobOlrSyV9lhyCGfRbcyTZzKUUtAds1JtDoPQEJpqTO95djXk-6PawQN0dP0T1WrRLDlgxURUMz9GQl9S3tzMWfjGDyPdNL6PtzbwrntvHcbKpANtQk1mH5ygqS9KQl0Pfq2-GwqTXLOKb-3tDlDAM1IfVj31RxFsVyqOV2rZQmjamTZh-Z0aoRAm2YYHz5C-uWsfHk18G9G3guXAuxPlstPfKgn1xOtQzaaqkMX0SpOnuU0upAUQxWwdo1Mlog8sfbC96LKSaRveXYPu9-JE

BrightTan commented 4 months ago

I've got the same problem....

brlx commented 4 days ago

Still a problem for us too. Might be a dupe of #4370