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


C# TextDocument.GetText方法代码示例

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


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

示例1: IndentLine

 public void IndentLine(TextDocument document, DocumentLine line)
 {
     if (document == null || line == null)
     {
         return;
     }
     DocumentLine previousLine = line.PreviousLine;
     if (previousLine != null)
     {
         ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);
         string indentation = document.GetText(indentationSegment);
         if (Program.OptionsObject.Editor_AgressiveIndentation)
         {
             string currentLineTextTrimmed = (document.GetText(line)).Trim();
             string lastLineTextTrimmed = (document.GetText(previousLine)).Trim();
             char currentLineFirstNonWhitespaceChar = ' ';
             if (currentLineTextTrimmed.Length > 0)
             {
                 currentLineFirstNonWhitespaceChar = currentLineTextTrimmed[0];
             }
             char lastLineLastNonWhitespaceChar = ' ';
             if (lastLineTextTrimmed.Length > 0)
             {
                 lastLineLastNonWhitespaceChar = lastLineTextTrimmed[lastLineTextTrimmed.Length - 1];
             }
             if (lastLineLastNonWhitespaceChar == '{' && currentLineFirstNonWhitespaceChar != '}')
             {
                 indentation += "\t";
             }
             else if (currentLineFirstNonWhitespaceChar == '}')
             {
                 if (indentation.Length > 0)
                 {
                     indentation = indentation.Substring(0, indentation.Length - 1);
                 }
                 else
                 {
                     indentation = string.Empty;
                 }
             }
             /*if (lastLineTextTrimmed == "{" && currentLineTextTrimmed != "}")
             {
                 indentation += "\t";
             }
             else if (currentLineTextTrimmed == "}")
             {
                 if (indentation.Length > 0)
                 {
                     indentation = indentation.Substring(0, indentation.Length - 1);
                 }
                 else
                 {
                     indentation = string.Empty;
                 }
             }*/
         }
         indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);
         document.Replace(indentationSegment, indentation);
     }
 }
开发者ID:not1ce111,项目名称:Spedit,代码行数:60,代码来源:EditorIndetation.cs

示例2: IndentLine

        /// <inheritdoc cref="IIndentationStrategy.IndentLine"/>
        public override void IndentLine(TextDocument document, DocumentLine line)
        {
            if (line?.PreviousLine == null)
                return;

            var prevLine = document.GetText(line.PreviousLine.Offset, line.PreviousLine.Length);
            var curLine = document.GetText(line.Offset, line.Length);
            int prev = CalcSpace(prevLine);

            var previousIsComment = prevLine.TrimStart().StartsWith("--", StringComparison.CurrentCulture);

            if (Regex.IsMatch(curLine, patternFull) && !previousIsComment)
            {
                var ind = new string(' ', prev);
                document.Insert(line.Offset, ind);
            }
            else if (Regex.IsMatch(prevLine, patternStart) && !previousIsComment)
            {
                var ind = new string(' ', prev + indent_space_count);
                document.Insert(line.Offset, ind);

                var found = false;
                for (int i = line.LineNumber; i < document.LineCount; ++i)
                {
                    var text = document.GetText(document.Lines[i].Offset, document.Lines[i].Length);

                    if (string.IsNullOrWhiteSpace(text) || text.TrimStart().StartsWith("--", StringComparison.CurrentCulture))
                        continue;

                    var sps = CalcSpace(text);

                    if (sps == prev && Regex.IsMatch(text, patternEnd))
                        found = true;
                }

                if (!found)
                {
                    var ntext = Environment.NewLine + new string(' ', prev) + "end";
                    var point = textEditor.SelectionStart;
                    document.Insert(line.Offset + ind.Length, ntext);
                    textEditor.SelectionStart = point;
                }
            }
            else
            {
                var ind = new string(' ', prev);
                if (line != null)
                    document.Insert(line.Offset, ind);
            }
        }
开发者ID:Konctantin,项目名称:Yanitta,代码行数:51,代码来源:LuaIndentationStrategy.cs

示例3: IndentLine

		/// <summary>
		/// Sets the indentation for the specified line.
		/// Usually this is constructed from the indentation of the previous line.
		/// </summary>
		/// <param name="document"></param>
		/// <param name="line"></param>
		public void IndentLine(TextDocument document, DocumentLine line)
		{
			var pLine = line.PreviousLine;
			if (pLine != null)
			{
				var segment = TextUtilities.GetWhitespaceAfter(document, pLine.Offset);
				var indentation = document.GetText(segment);

				var amount = HtmlParser.CountUnclosedTags(document.GetText(pLine));
				if (amount > 0)
					indentation += new string('\t', amount);

				document.Replace(TextUtilities.GetWhitespaceAfter(document, line.Offset), indentation);
			}
		}
开发者ID:andrebelanger,项目名称:HTMLEditor,代码行数:21,代码来源:HtmlIndentationStrategy.cs

示例4: ConvertTextDocumentToBlock

		public static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
		{
			if (document == null)
				throw new ArgumentNullException("document");
//			Table table = new Table();
//			table.Columns.Add(new TableColumn { Width = GridLength.Auto });
//			table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
//			TableRowGroup trg = new TableRowGroup();
//			table.RowGroups.Add(trg);
			Paragraph p = new Paragraph();
			foreach (DocumentLine line in document.Lines) {
				int lineNumber = line.LineNumber;
//				TableRow row = new TableRow();
//				trg.Rows.Add(row);
//				row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
				HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
				if (highlighter != null) {
					HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
					int lineStartOffset = line.Offset;
					foreach (HighlightedSection section in highlightedLine.Sections)
						inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
				}
//				Paragraph p = new Paragraph();
//				row.Cells.Add(new TableCell(p));
				p.Inlines.AddRange(inlineBuilder.CreateRuns());
				p.Inlines.Add(new LineBreak());
			}
			return p;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:29,代码来源:DocumentPrinter.cs

示例5: SearchBackward

        static DToken SearchBackward(TextDocument doc, int caretOffset, CodeLocation caret,out DToken lastToken)
        {
            var ttp = doc.GetText(0, caretOffset);
            var sr = new StringReader(ttp);
            var lexer = new Lexer(sr);
            lexer.NextToken();

            var stk=new Stack<DToken>();

            while (lexer.LookAhead.Kind!=DTokens.EOF)
            {
                if (lexer.LookAhead.Kind == DTokens.OpenParenthesis || lexer.LookAhead.Kind==DTokens.OpenSquareBracket || lexer.LookAhead.Kind==DTokens.OpenCurlyBrace)
                    stk.Push(lexer.LookAhead);

                else if (lexer.LookAhead.Kind == DTokens.CloseParenthesis || lexer.LookAhead.Kind == DTokens.CloseSquareBracket || lexer.LookAhead.Kind == DTokens.CloseCurlyBrace)
                {
                    if (stk.Peek().Kind == getOppositeBracketToken( lexer.LookAhead.Kind))
                        stk.Pop();
                }

                lexer.NextToken();
            }

            lastToken = lexer.CurrentToken;

            sr.Close();
            lexer.Dispose();

            if (stk.Count < 1)
                return null;

            return stk.Pop();
        }
开发者ID:cessationoftime,项目名称:D-IDE,代码行数:33,代码来源:DBracketSearcher.cs

示例6: CreateNewFoldings

 protected override IEnumerable<NewFolding> CreateNewFoldings(TextDocument document)
 {
     string name = null;
     int? startOffset = null;
     int? endOffset = null;
     foreach (var line in document.Lines)
     {
         var text = document.GetText(line);
         var isFunction = _functionRegex.IsMatch(text);
         if (isFunction)
         {
             if (startOffset != null && endOffset != null)
             {
                 yield return new NewFolding { StartOffset = startOffset.Value, EndOffset = endOffset.Value, Name = name, IsDefinition = true };
             }
             name = text;
             startOffset = line.Offset;
             endOffset = null;
             continue;
         }
         if (startOffset == null || string.IsNullOrWhiteSpace(text)) continue;
         var firstChar = text.First(c => !char.IsWhiteSpace(c));
         if (!firstChar.Equals(Gherkin.Comment) && !firstChar.Equals(Gherkin.Tag)) endOffset = line.EndOffset;
     }
     if (startOffset != null && endOffset != null)
     {
         yield return new NewFolding { StartOffset = startOffset.Value, EndOffset = endOffset.Value, Name = name, IsDefinition = true };
     }
 }
开发者ID:testpulse,项目名称:Pickle-Studio,代码行数:29,代码来源:GherkinFoldingStrategy.cs

示例7: IsBracketOnly

 bool IsBracketOnly(TextDocument document, DocumentLine documentLine)
 {
     var lineText = document.GetText(documentLine).Trim();
     return lineText == "{" || string.IsNullOrEmpty(lineText)
         || lineText.StartsWith("//", StringComparison.Ordinal)
         || lineText.StartsWith("/*", StringComparison.Ordinal)
         || lineText.StartsWith("*", StringComparison.Ordinal)
         || lineText.StartsWith("'", StringComparison.Ordinal);
 }
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:9,代码来源:BracketSearcher.cs

示例8: GetText

		/// <inheritdoc/>
		public override string GetText(TextDocument document)
		{
			StringBuilder b = new StringBuilder();
			foreach (ISegment s in this.Segments) {
				if (b.Length > 0)
					b.AppendLine();
				b.Append(document.GetText(s));
			}
			return b.ToString();
		}
开发者ID:SiGhTfOrbACQ,项目名称:O2.Platform.Projects,代码行数:11,代码来源:RectangleSelection.cs

示例9: CreateNewFoldings

        /// <summary>
        /// Create <see cref="NewFolding"/>s for the specified document.
        /// </summary>
        public IEnumerable<NewFolding> CreateNewFoldings(TextDocument document, out int firstErrorOffset)
        {
            firstErrorOffset = -1;

            var foldings = new List<NewFolding>();
            var stack = new Stack<int>();

            foreach (var line in document.Lines)
            {
                var text = document.GetText(line.Offset, line.Length);

                // комментарии пропускаем
                if (commentPattern.IsMatch(text))
                    continue;

                foreach (Match match in startPattern.Matches(text))
                {
                    var element = match.Groups["start"];
                    if (element.Success)
                    {
                        stack.Push(line.EndOffset);
                    }
                }

                foreach (Match match in endPattern.Matches(text))
                {
                    var element = match.Groups["end"];
                    if (element.Success)
                    {
                        if (stack.Count > 0)
                        {
                            var first = stack.Pop();
                            var folding = new NewFolding(first, line.EndOffset);
                            foldings.Add(folding);
                        }
                        else
                        {
                            firstErrorOffset = line.Offset;
                        }
                    }
                }
            }

            if (stack.Count > 0)
            {
                firstErrorOffset = stack.Pop();
            }

            foldings.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
            return foldings;
        }
开发者ID:Konctantin,项目名称:Yanitta,代码行数:54,代码来源:LuaFoldingStrategy.cs

示例10: IndentLine

		/// <inheritdoc/>
		public virtual void IndentLine(TextDocument document, DocumentLine line)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (line == null)
				throw new ArgumentNullException("line");
			DocumentLine previousLine = line.PreviousLine;
			if (previousLine != null) {
				ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);
				string indentation = document.GetText(indentationSegment);
				// copy indentation to line
				indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);
				document.Replace(indentationSegment, indentation);
			}
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:16,代码来源:DefaultIndentationStrategy.cs

示例11: IndentLine

		/// <inheritdoc/>
		public virtual void IndentLine(TextDocument document, DocumentLine line)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (line == null)
				throw new ArgumentNullException("line");
			DocumentLine previousLine = line.PreviousLine;
			if (previousLine != null) {
				ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);
				string indentation = document.GetText(indentationSegment);
				// copy indentation to line
				indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);
				document.Replace(indentationSegment.Offset, indentationSegment.Length, indentation,
				                 OffsetChangeMappingType.RemoveAndInsert);
				// OffsetChangeMappingType.RemoveAndInsert guarantees the caret moves behind the new indentation.
			}
		}
开发者ID:bbqchickenrobot,项目名称:AvalonEdit,代码行数:18,代码来源:DefaultIndentationStrategy.cs

示例12: IndentLine

        /// <inheritdoc/>
        public virtual void IndentLine(TextDocument document, DocumentLine line)
        {
            if (document == null)
                throw new ArgumentNullException(nameof(document));
            if (line == null)
                throw new ArgumentNullException(nameof(line));

            if (line.PreviousLine != null)
            {
                var indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.PreviousLine.Offset);
                var indentation = document.GetText(indentationSegment);
                // copy indentation to line
                indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);

                document.Replace(indentationSegment, indentation);
            }
        }
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:18,代码来源:DefaultIndentationStrategy.cs

示例13: IndentLine

        public void IndentLine(TextDocument document, DocumentLine line, bool TakeCaret)
        {
            if (line.PreviousLine == null)
                return;

            if (!DSettings.Instance.EnableSmartIndentation)
            {
                var prevIndent = ReadRawLineIndentation(document.GetText(line));

                RawlyIndentLine(prevIndent, document, line);

                return;
            }

            var tr=document.CreateReader();
            var block = CalculateIndentation(tr, line.LineNumber);
            tr.Close();

            RawlyIndentLine(block != null ? block.GetLineIndentation(line.LineNumber) : 0, document, line);
        }
开发者ID:rumbu13,项目名称:D-IDE,代码行数:20,代码来源:DIndentationStrategy.cs

示例14: GetCompletions

        public void GetCompletions(TextDocument doc, int Offset, IList<ICompletionData> data)
        {    
  
            // match only last N chars
            int N = Math.Min(Offset, 200);
            string s = doc.GetText(Offset - N, N);

            foreach (CodeEnvironment ee in envs)
            {
                if ( ee.MatchEnv(s) )
                {
                    foreach (MyCompletionData snipp in ee.snippets)
                    {
                        data.Add(snipp);
                    }
                }
            }
    

            //data.Add(new MyCompletionData("draw"));
            //data.Add(new MyCompletionData("fill"));
            //data.Add(new MyCompletionData("minimum size"));
        }
开发者ID:JoeyEremondi,项目名称:tikzedt,代码行数:23,代码来源:CodeCompleter.cs

示例15: FoldTitle

 internal override string FoldTitle(FoldingSection section, TextDocument doc)
 {
     var array = Regex.Split(section.Title, "æ");
     var offset = section.StartOffset + array[0].Length;
     var length = section.Length - (array[0].Length + array[1].Length);
     return doc.GetText(offset, length);
 }
开发者ID:mookiejones,项目名称:miEditor,代码行数:7,代码来源:Fanuc.cs


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