Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to add standard DOM event listener to monaco editor

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?

like image 882
thejavo Avatar asked Sep 15 '25 16:09

thejavo


1 Answers

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 !")
})
like image 116
Om Prakash Sharma Avatar answered Sep 17 '25 04:09

Om Prakash Sharma