Reputation: 105
I'm trying to add focus / blur standard DOM events to monaco-editor.
editor.addEventListener("blur", function(){
<do something>
});
I received the following answer:
Uncaught TypeError: editor.addEventListener is not a function
Also tried jquery
$(editor).on("blur", function(){
<do something>
});
No errors this time, but nothing happens. I mean, the event didn't fire.
I've also tried to attach the listeners to editor container div, but same results.
any ideas?
Upvotes: 4
Views: 4761
Reputation: 1840
In Monaco Editor
To listen for focus event, you can use
editor.onDidFocusEditorWidget(()=>{
console.log("Focus event triggerd !")
})
and For Blur event, you can use
editor.onDidBlurEditorWidget(()=>{
console.log("Blur event triggerd !")
})
Upvotes: 14
Reputation: 105
Found them finally. Monaco Editor provides with two events:
editor.onDidBlurEditor(()=>{
<do something>
});
editor.onDidFocusEditor(()=>{
<do something>
});
I've finally discover them with Chrome DevTools checking the object properties. the api documentation available on project's git page is chinese for me.
Upvotes: 2