当前位置: 首页>>代码示例>>C#>>正文


C# TextDocument.GetLineByOffset方法代码示例

本文整理汇总了C#中ICSharpCode.AvalonEdit.Document.TextDocument.GetLineByOffset方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.GetLineByOffset方法的具体用法?C# TextDocument.GetLineByOffset怎么用?C# TextDocument.GetLineByOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.AvalonEdit.Document.TextDocument的用法示例。


在下文中一共展示了TextDocument.GetLineByOffset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateHtmlFragment

        /// <summary>
        /// Creates a HTML fragment from a part of a document.
        /// </summary>
        /// <param name="document">The document to create HTML from.</param>
        /// <param name="highlighter">The highlighter used to highlight the document. <c>null</c> is valid and will create HTML without any highlighting.</param>
        /// <param name="segment">The part of the document to create HTML for. You can pass <c>null</c> to create HTML for the whole document.</param>
        /// <param name="options">The options for the HTML creation.</param>
        /// <returns>HTML code for the document part.</returns>
        public static string CreateHtmlFragment(TextDocument document, IHighlighter highlighter, ISegment segment, HtmlOptions options)
        {
            if (document == null)
                throw new ArgumentNullException("document");
            if (options == null)
                throw new ArgumentNullException("options");
            if (highlighter != null && highlighter.Document != document)
                throw new ArgumentException("Highlighter does not belong to the specified document.");
            if (segment == null)
                segment = new SimpleSegment(0, document.TextLength);

            StringBuilder html = new StringBuilder();
            int segmentEndOffset = segment.EndOffset;
            DocumentLine line = document.GetLineByOffset(segment.Offset);
            while (line != null && line.Offset < segmentEndOffset) {
                HighlightedLine highlightedLine;
                if (highlighter != null)
                    highlightedLine = highlighter.HighlightLine(line.LineNumber);
                else
                    highlightedLine = new HighlightedLine(document, line);
                SimpleSegment s = segment.GetOverlap(line);
                if (html.Length > 0)
                    html.AppendLine("<br>");
                html.Append(highlightedLine.ToHtml(s.Offset, s.EndOffset, options));
                line = line.NextLine;
            }
            return html.ToString();
        }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:36,代码来源:HtmlClipboard.cs

示例2: SearchDefinition

 void SearchDefinition(TextDocument document, BracketSearchResult result)
 {
     if (document.GetCharAt(result.OpeningOffset) != '{')
         return;
     // get line
     var documentLine = document.GetLineByOffset(result.OpeningOffset);
     while (documentLine != null && IsBracketOnly(document, documentLine))
         documentLine = documentLine.PreviousLine;
     if (documentLine != null)
     {
         result.DefinitionHeaderOffset = documentLine.Offset;
         result.DefinitionHeaderLength = documentLine.Length;
     }
 }
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:14,代码来源:BracketSearcher.cs

示例3: SkipComment

        /// <summary>
        /// Skips any comments that start at the current offset.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="offset">The offset.</param>
        /// <returns>The index of the next character after the comments.</returns>
        private static int SkipComment(TextDocument document, int offset)
        {
            if (offset >= document.TextLength - 1)
                return offset + 1;

            char current = document.GetCharAt(offset);
            char next = document.GetCharAt(offset + 1);

            if (current == '/' && next == '/')
            {
                // Skip line comment "//"
                var line = document.GetLineByOffset(offset);
                int offsetOfNextLine = line.Offset + line.TotalLength;
                return offsetOfNextLine;
            }

            if (current == '/' && next == '*')
            {
                // Skip block comment "/* ... */"
                offset += 2;
                while (offset + 1 < document.TextLength)
                {
                    if (document.GetCharAt(offset) == '*' && document.GetCharAt(offset + 1) == '/')
                    {
                        offset = offset + 2;
                        break;
                    }
                    offset++;
                }
                return offset;
            }

            return offset + 1;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:40,代码来源:CSharpFoldingStrategy.cs

示例4: MarkRegion

        /// <summary>
        /// Marks the region that starts at the given offset.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="folds">The fold markers.</param>
        /// <returns>The index of the next character after the region.</returns>
        private static int MarkRegion(TextDocument document, int offset, List<NewFolding> folds)
        {
            if (offset >= document.TextLength)
                return offset;

            if (document.GetCharAt(offset) == '#')
            {
                int startOffset = offset;
                offset++;
                string word = TextUtilities.GetIdentifierAt(document, offset);
                if (word == "region")
                {
                    offset += "region".Length;

                    // Find label
                    var line = document.GetLineByOffset(offset);
                    int lineEnd = line.Offset + line.Length;
                    int labelLength = lineEnd - offset;
                    string label = document.GetText(offset, labelLength);
                    label = label.Trim();
                    if (label.Length == 0)
                        label = "#region";

                    // Find and mark subregions
                    offset = FindAndMarkRegions(document, lineEnd, folds);

                    if (offset <= document.TextLength)
                    {
                        AddFold(document, folds, startOffset, offset, label);
                        offset++;
                    }
                }
            }
            else
            {
                offset++;
            }
            return offset;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:46,代码来源:CSharpFoldingStrategy.cs

示例5: IsMultiline

		/// <summary>
		/// Gets whether the selection is multi-line.
		/// </summary>
		public virtual bool IsMultiline(TextDocument document)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			ISegment surroundingSegment = this.SurroundingSegment;
			if (surroundingSegment == null)
				return false;
			int start = surroundingSegment.Offset;
			int end = start + surroundingSegment.Length;
			return document.GetLineByOffset(start) != document.GetLineByOffset(end);
		}
开发者ID:pusp,项目名称:o2platform,代码行数:14,代码来源:Selection.cs


注:本文中的ICSharpCode.AvalonEdit.Document.TextDocument.GetLineByOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。