Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listening to text selection changes in monaco editor

Is there an event in monaco editor for text selection ? I need to respond to a user selecting part of the code in editor?

Is there a better solution to using timer to get ranges for selection ?

Documents don't seem to mention about it.

like image 369
Nishant Avatar asked Feb 26 '18 05:02

Nishant


1 Answers

You can use onDidChangeCursorPosition or onDidChangeCursorSelection. to listen for such an event.

var editor = monaco.editor.create(document.getElementById("container"), {
    value: "function hello() {\n\talert('Hello world!');\n}",
    language: "javascript"
});

editor.onDidChangeCursorPosition((e) => {
    console.log(JSON.stringify(e));
});

editor.onDidChangeCursorSelection((e) => {
    console.log(JSON.stringify(e));
});
like image 117
rcjsuen Avatar answered Sep 29 '22 08:09

rcjsuen