Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After monaco multi-instance destroys one instance, another instance cannot get the content[Bug] #3490

Closed
2 tasks
MichaelHao25 opened this issue Jan 6, 2023 · 4 comments
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@MichaelHao25
Copy link

MichaelHao25 commented Jan 6, 2023

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 

<button id="dispose">b.dispose</button>
<div id="container" style="height: 300px"></div>
<div id="container2" style="height: 300px"></div>

js


const a = monaco.editor.create(document.getElementById('container'), {
	value: "function hello() {\n\talert('Hello world!');\n}",
	language: 'javascript'
});
  a.addCommand(
          /** command */
          monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS,
          () => {
            const model = a.getModel();
              console.log('model', model.id);
 
}
        );
const b = monaco.editor.create(document.getElementById('container2'), {
	value: "function hello() {\n\talert('Hello world!');\n}",
	language: 'javascript'
});

b.addCommand(
          /** command */
          monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS,
          () => {
            const model = b.getModel();
              console.log('model', model.id);
            
}
        );

        document.getElementById('dispose').onclick=()=>{
            b.dispose();
        }


### Reproduction Steps

1. click button b.dispose
2. a instance press CtrlCmd +  KeyS get model is null;



### Actual (Problematic) Behavior

i'm dispose instance b , why  instance a content not get ?

### Expected Behavior

i'm dispose instance b , normal get instance a content;

### Additional Context

_No response_
@MichaelHao25
Copy link
Author

pls help me。。

@hediet hediet added info-needed Issue requires more information from poster and removed info-needed Issue requires more information from poster labels Jan 9, 2023
@CGNonofr
Copy link
Contributor

CGNonofr commented Jan 24, 2023

I think you misunderstood the issue. The issue is that commands are not linked to an editor but global even though you add them using an editor instance

@hediet hediet added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Feb 2, 2023
@MichaelHao25
Copy link
Author

I think you misunderstood the issue. The issue is that commands are not linked to an editor but global even though you add them using an editor instance

Please help me how to solve this problem,tks

@CGNonofr
Copy link
Contributor

CGNonofr commented Feb 7, 2023

I suggest you use the addAction api instead

const a = monaco.editor.create(document.getElementById('container'), {
    value: "function hello() {\n\talert('Hello world!');\n}",
    language: 'javascript'
});
a.addAction({
    id: 'save',
    label: 'Save',
    keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
    run(editor) {
        console.log(editor.getModel().id)
    }
})
const b = monaco.editor.create(document.getElementById('container2'), {
    value: "function hello() {\n\talert('Hello world!');\n}",
    language: 'javascript'
});

b.addAction({
    id: 'save',
    label: 'Save',
    keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
    run(editor) {
        console.log(editor.getModel().id)
    }
})

document.getElementById('dispose').onclick = () => {
    b.dispose();
}

@microsoft microsoft locked and limited conversation to collaborators Mar 3, 2023
@hediet hediet converted this issue into discussion #3686 Mar 3, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants