AvalonEdit - 规则集跨度

发布于 2024-09-28 14:56:52 字数 54 浏览 1 评论 0原文

如何检查某个位置的单词是否在 xshd 规则集的 Span[i] 中?

谢谢!

How to check if a word at a position is in a Span[i] of the xshd-ruleset?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

未蓝澄海的烟 2024-10-05 14:56:52

有两种可能的方法可以从突出显示引擎获取信息:

突出显示引擎仅在每行的开头存储“跨度堆栈”。您可以使用 DocumentHighlighter.GetSpanStack 方法来检索它。

var documentHighlighter = textEditor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter;
bool isInComment = documentHighlighter.GetSpanStack(1)
             .Any(s => s.SpanColor != null && s.SpanColor.Name == "Comment");

如果第 1 行的结尾(= 第 2 行的开头)位于多行注释内,则返回 true。

要获得行内更详细的结果,您必须运行荧光笔。

int off = document.GetOffset(7, 22);
HighlightedLine result = documentHighlighter.HighlightLine(7);
bool isInComment = result.Sections.Any(s => s.Offset <= off
                                         && s.Offset+s.Length >= off
                                         && s.Color.Name == "Comment");

当然,只有在命名了这些颜色的情况下,通过颜色识别跨度/部分才能可靠地工作。并非所有内置突出显示都已更新为使用命名颜色,因此请首先检查 .xshd 文件。

There are two possible ways to get information from the highlighting engine:

The highlighting engine only stores the "span stack" at the start of each line. You can use the DocumentHighlighter.GetSpanStack method to retrieve it.

var documentHighlighter = textEditor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter;
bool isInComment = documentHighlighter.GetSpanStack(1)
             .Any(s => s.SpanColor != null && s.SpanColor.Name == "Comment");

This will return true if the end of line 1 (= start of line 2) is inside a multiline comment.

For more detailed results inside lines, you'll have to run the highlighter.

int off = document.GetOffset(7, 22);
HighlightedLine result = documentHighlighter.HighlightLine(7);
bool isInComment = result.Sections.Any(s => s.Offset <= off
                                         && s.Offset+s.Length >= off
                                         && s.Color.Name == "Comment");

Of course, identifying spans/sections by color only works reliably if those colors are named. Not all built-in highlightings have been updated to use named colors, so please check the .xshd files first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文