question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Multiple editor instances only latest created instance is working properly

See original GitHub issue

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 Code

/* HTML CONTENT
<div id="container" style="height: 50%"></div>
<div id="container2" style="height: 50%"></div>
*/

const model = monaco.editor.createModel("function hello() {\n\talert('Hello world!');\n}", 'javascript');
const model1 = monaco.editor.createModel("function test() {\n\talert('Hello test!');\n}", 'javascript');
const editor = monaco.editor.create(document.getElementById('container'), {
    model
});
const editor2 = monaco.editor.create(document.getElementById('container2'), {
    model:model1
});

editor.addCommand(monaco.KeyMod.CtrlCmd|monaco.KeyMod.Shift|monaco.KeyCode.KeyF, ()=> {
    const pos = editor.getPosition();
    console.log('pos', pos)
});
editor2.addCommand(monaco.KeyMod.CtrlCmd|monaco.KeyMod.Shift|monaco.KeyCode.KeyF, ()=> {
    const pos = editor2.getPosition();
    console.log('pos2', pos)
});

Actual Behavior

Triggering crtl + shift + f in the first instance, the custom command of the second instance will be triggered.

Expected Behavior

Triggering crtl + shift + f in any editor instance should trigger the command of the correct editor instance.

Additional Context

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:13
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
ihqtimcommented, Nov 24, 2022

This has also been impacting us for the last few months since updating to a newer release of the editor (we are currently using 0.34.1). In our case a user may have multiple editors open (i.e. editing multiple source file). We use custom key binding CTRL + S to save the model displayed in the “active” editor. In prior versions this worked as expected, now the CTRL + S command is routed to the most-recently-opened editor instance rather than the active/in-focus editor instance, meaning that:

  • users are accidently saving files they do not intend to save, and
  • files that users think they have saved are not actually saved (i.e. they lose work) This is making our users quite unhappy.
3reactions
dingiyancommented, Jul 20, 2022

Hello everyone, Several months have passed. How is this problem fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

multiple instance of visual studio - Unity Forum
First, check that the Visual Studio Editor package is updated. Check in Windows > Package Manager of the Unity Editor to update this....
Read more >
CKEditor instance already exists - Stack Overflow
I am using this before my calls to create an instance (ones per page load). Not sure how this affects memory handling and...
Read more >
When running multiple instances of Visual Studio at the same ...
When running multiple instances of Visual Studio at the same time, executing a NEW instance of VS can cause in one, or more,...
Read more >
Edit main components - Figma Help Center
This will also update any other instances of that component. You can only push overrides if the main component is in the same...
Read more >
Open Excel files in separate windows and multiple instances
Create a new Excel instance using the taskbar. The fastest way to open a new instance of Excel is this: Right-click the Excel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found