如何在 Scintilla 中突出显示文本?
我正在使用 Scintilla 编写一个编辑器。
我已经在使用词法分析器来进行自动语法突出显示,但现在我想标记搜索结果。 如果我只想标记一个命中,我可以在那里设置选择,但是,我想标记(例如用黄色背景)所有命中。
我用 Perl 写这篇文章,但如果你有其他语言的建议,那也很酷。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
“示例”编辑器站点使用书签功能为与搜索结果匹配的所有行添加书签。
The "sample" editor scite uses the bookmark feature to bookmark all the lines that match the search result.
此解决方案适用于 c#:
调用很简单,在本例中以 @ 开头的单词将突出显示:
This solution works in c#:
Call is simple, in this example the words beginning with @ will be highlighted:
我使用 指标 来突出显示搜索结果。
I used Indicators to highlight search results.
您是否阅读过 Scintilla 文档中的标记参考?
该参考文献可能有点晦涩,因此我建议您也看一下 SciTE 的源代码。 该文本编辑器最初是 Scintilla 的测试平台。 它已发展成为一个成熟的编辑器,但对于 Scintilla 的所有内容来说,它仍然是一个很好的实现参考。
在我们的特定情况下,“查找”对话框中有一个“全部标记”按钮。 您可以在 SciTEBase::MarkAll() 方法中找到它的实现。 此方法仅在搜索结果上循环(直到在第一个搜索结果上循环(如果有)),并在找到的行上放置书签(并且可以选择在找到的项目上设置指示器)。
找到的行是使用 SCI_LINEFROMPOSITION(posFound) 获取的,书签只是对 SCI_MARKERADD(lineno,markerBookmark) 的调用。
请注意,该标记可以是页边距中的符号,或者如果不与页边距关联,它将突出显示整行。
HTH。
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.