How to highligh specific text in the monaco editor

Viewed 23

I am highlighting the text in the textarea using the following approach in angular.

https://stackblitz.com/edit/angular-textarea-highlight?file=src%2Fapp%2Fapp.component.ts

How can we achieve the same in monaco editor. Is there a way I can use Monaco editor to do this?

My Approach:

 const acceptedList = ['do', 'have'];
    //  let editor1 = monaco.editor.create( ... 
    let model = editor1.getModel();
    for (let i = 0; i < model.getLineCount(); i++) {
        let line = model.getLineContent(i);
        // here highlight the line if contains from acceptedList
    }

Trying to loop through the lines and highlight if it matches our condition. Is it the right approach? how can we highlight the line in monaco editor?

0 Answers
Related