gpt4 book ai didi

c# - AvalonEdit:确定您是否在评论中

转载 作者:行者123 更新时间:2023-11-30 22:23:19 24 4
gpt4 key购买 nike

对于 AvalonEdit,我在 xshd 文件中定义了“注释”。现在,在我的程序中,我想确定给定的偏移量是在注释内部还是外部。

我确实在网上找到了一些代码,即:
http://community.sharpdevelop.net/forums/t/12793.aspx

但是,我不知道如何从我的 AvalonEdit-Object 接收必要的对象(如 CurrentContext)。

我希望以前有人创建过这样的函数。你能发布一些代码或指出正确的方向吗? (文档等)

最佳答案

我不确定该示例中的“当前上下文”是什么,但它仅用于通过 IHighlighter 访问服务容器。您可以直接从 TextEditor 中获取:

bool IsInComment(int line, int column)
{
IHighlighter highlighter = textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;
if (highlighter == null)
return false;
int off = textEditor.Document.GetOffset(line, column);
HighlightedLine result = highlighter.HighlightLine(document.GetLineByNumber(line));
return result.Sections.Any(s => s.Offset <= off && s.Offset+s.Length >= off && s.Color.Name == "Comment");
}

关于c# - AvalonEdit:确定您是否在评论中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13441271/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com