本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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 };
}
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
}
示例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.
}
}
示例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);
}
}
示例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);
}
示例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"));
}
示例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);
}