Mono.TextEditor高亮行 [英] Mono.TextEditor highlight line
问题描述
我正在MonoDevelop中的Mono中制作一个Pascal代码编辑器.我正在使用Mono.TextEditor
作为代码编辑器小部件.但是,我找不到如何在窗口小部件中突出显示一行.
编译后,我收集发生错误的行号,因此我要用红色突出显示它们.我发现了
I am making a pascal code editor in Mono in MonoDevelop. I am using Mono.TextEditor
as a code editor widget. However, I cannot find how to highlight a line in the widget.
After compilation, I collect line numbers where errors occur, and so I want to highlight them in red. I found
Mono.TextEditor.LineBackgroundMarker
似乎与我想做的事情有关,但是我找不到在哪里以及如何使用它.
which seems to relate to what I want to do, but I cannot find where and how to use it.
我正在研究的另一个选项是ViBuilder,但我什至不知道如何使用它.我可以想到两种方法来解决此问题:
Another option I was looking into was ViBuilder, but I don't even know how to use that. I can think of two ways to solve this problem:
- 只需突出显示
-
将一行标记为错误,因为默认样式包括:
- Simply make highlight
Mark a line as error, as default style includes:
{ "name": "Underline(Error)", "color":"invalid-red" }
这似乎也是一个可能的解决方案.
which also seems to be a possible solution.
推荐答案
您可以通过在基础文档中添加标记来突出显示文本编辑器中的行.使用TextDocument.AddMarker方法,如下所示:
You can highlight lines in the text editor by adding markers to the underlying document. Use the TextDocument.AddMarker method, as follows:
TextEditor textEditor;
var marker = new Mono.TextEditor.LineBackgroundMarker();
int lineNumber = ...;
textEditor.Document.AddMarker(lineNumber, marker);
textEditor.QueueDraw();
还可以查看Mono.TextEditor.StyleTextMarker类.此类已经具有您要查找的属性"BackgroundColor"/"Color".下划线可能必须手动完成(例如,通过从StyleTextMarker继承并覆盖Draw方法).
Also have a look at the Mono.TextEditor.StyleTextMarker class. This class has already the properties "BackgroundColor" / "Color" that you are looking for. Underlining may have to be done manually (for example by inheriting from StyleTextMarker and overriding the Draw method).
这篇关于Mono.TextEditor高亮行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!