For example I have some text in ace-editor and a list of ranges of rows and lines in text where highlightings should happened. Like this (they're bolded):
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam. Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh.
How to highlight these words by using ace-editor API?
How to highlight multiple lines?
Click the first file or folder you want to select. Hold down the Shift key, select the last file or folder, and then let go of the Shift key. Hold down the Ctrl key and click any other file(s) or folder(s) you would like to add to those already selected.
Click the first item, then press the SHIFT key and hold it. Click the last item and release the SHIFT key. To select adjacent items, you can also use the mouse. Click the left mouse button on the first item, hold the mouse button, move the cursor to the last item and then release the mouse button.
To select contiguous items in the list, navigate to the first item you want to select, then hold down the SHIFT key and press the DOWN ARROW key until the last item you want to select is highlighted.
To select multiple areas that aren't next to each other, make your first selection, hold down CTRL, and then select any other items you want.
Finally I've got the answer.
Highlight the word:
var range = new Range(rowStart, columnStart, rowEnd, columnEnd);
var marker = editor.getSession().addMarker(range,"ace_selected_word", "text");
Remove the highlighted word:
editor.getSession().removeMarker(marker);
Highlight the line:
editor.getSession().addMarker(range,"ace_active_line","background");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With