Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I highlight text in Scintilla?

I am writing an editor using Scintilla.

I am already using a lexer to do automatic syntax highlighting but now I would like to mark search results. If I want to mark only one hit I can set the selection there, however, I would like to mark (e.g. with yellow background) all the hits.

I writing this in Perl but if you have suggestions in other languages that would be cool as well.

like image 704
szabgab Avatar asked Sep 18 '08 13:09

szabgab


People also ask

How do I highlight text in a TXT file?

If you want to highlight one word at a time, press Ctrl while holding down Shift , and then press Left arrow or Right arrow . If you want to highlight a whole line of text, move your cursor to the start of the line, hold Shift , and then press Down arrow .


2 Answers

Have you read the Markers reference in Scintilla doc? This reference can be a bit obscure, so I advise to take a look at the source code of SciTE as well. This text editor was originally a testbed for Scintilla. It grown to a full fledged editor, but it is still a good implementation reference for all things Scintilla.

In our particular case, there is a Mark All button in the Find dialog. You can find its implementation in SciTEBase::MarkAll() method. This method only loops on search results (until it loops on the first search result, if any) and puts a bookmark on the found lines (and optionally set an indicator on the found items). The found line is gotten using SCI_LINEFROMPOSITION(posFound), the bookmark is just a call to SCI_MARKERADD(lineno, markerBookmark). Note that the mark can be symbol in a margin, or if not associated to a margin, it will highlight the whole line.

HTH.

like image 86
PhiLho Avatar answered Sep 21 '22 03:09

PhiLho


The "sample" editor scite uses the bookmark feature to bookmark all the lines that match the search result.

like image 21
Pat Avatar answered Sep 20 '22 03:09

Pat