简体   繁体   中英

Highlight word in Ace Editor

I'm using Ace Editor and specifically react-ace . I want to highlight a certain word.

I am aware that I can define custom syntax highlighting rules but it seems more hassle than it's worth compared to updating a marker every time the input changes (which in my case, should not be too often).

For a marker, I need the Range of the word - startRow , startCol , endRow , endCol . I tried using find() for this, and it seems to indeed return the desired range of a term/regex I search for, but this seems to a high-level command which performs what you would expect from a "find" operation in an editor - highlights the term and jumps to it.

How would I go about retrieving the Range of a word in an Ace Editor?

There is an undocumented preventScroll option to find that returns the range ace/editor.js#L2593-L2594 , and you can also use the $search directly to find all ranges similar to ace/multi_select.js#L568 . It's worth noting that this would not be the most efficient and performant method to highlight large number of ranges, but that depends on specific details of the problem you are trying to solve which are not stated in the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM