本文整理汇总了C#中TextEditor.GetTextAt方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.GetTextAt方法的具体用法?C# TextEditor.GetTextAt怎么用?C# TextEditor.GetTextAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor.GetTextAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixLineStart
public bool FixLineStart (TextEditor textEditorData, ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine stateTracker, int lineNumber)
{
if (lineNumber > 1) {
var line = textEditorData.GetLine (lineNumber);
if (line == null)
return false;
var prevLine = textEditorData.GetLine (lineNumber - 1);
if (prevLine == null)
return false;
string trimmedPreviousLine = textEditorData.GetTextAt (prevLine).TrimStart ();
//xml doc comments
//check previous line was a doc comment
//check there's a following line?
if (trimmedPreviousLine.StartsWith ("///", StringComparison.Ordinal)) {
if (textEditorData.GetTextAt (line.Offset, line.Length).TrimStart ().StartsWith ("///", StringComparison.Ordinal))
return false;
//check that the newline command actually inserted a newline
textEditorData.EnsureCaretIsNotVirtual ();
var nextLineSegment = textEditorData.GetLine (lineNumber + 1);
string nextLine = nextLineSegment != null ? textEditorData.GetTextAt (nextLineSegment).TrimStart () : "";
if (trimmedPreviousLine.Length > "///".Length || nextLine.StartsWith ("///", StringComparison.Ordinal)) {
var insertionPoint = textEditorData.CaretOffset;
textEditorData.InsertText (insertionPoint, "/// ");
textEditorData.CaretOffset = insertionPoint + "/// ".Length;
return true;
}
//multi-line comments
} else if (stateTracker.IsInsideMultiLineComment) {
if (textEditorData.GetTextAt (line.Offset, line.Length).TrimStart ().StartsWith ("*", StringComparison.Ordinal))
return false;
textEditorData.EnsureCaretIsNotVirtual ();
string commentPrefix = string.Empty;
if (trimmedPreviousLine.StartsWith ("* ", StringComparison.Ordinal)) {
commentPrefix = "* ";
} else if (trimmedPreviousLine.StartsWith ("/**", StringComparison.Ordinal) || trimmedPreviousLine.StartsWith ("/*", StringComparison.Ordinal)) {
commentPrefix = " * ";
} else if (trimmedPreviousLine.StartsWith ("*", StringComparison.Ordinal)) {
commentPrefix = "*";
}
int indentSize = line.GetIndentation (textEditorData).Length;
var insertedText = prevLine.GetIndentation (textEditorData) + commentPrefix;
textEditorData.ReplaceText (line.Offset, indentSize, insertedText);
textEditorData.CaretOffset = line.Offset + insertedText.Length;
return true;
} else if (wasInStringLiteral) {
var lexer = new ICSharpCode.NRefactory.CSharp.Completion.CSharpCompletionEngineBase.MiniLexer (textEditorData.GetTextAt (0, prevLine.EndOffset).TrimEnd ());
lexer.Parse ();
if (!lexer.IsInString)
return false;
textEditorData.EnsureCaretIsNotVirtual ();
textEditorData.InsertText (prevLine.Offset + prevLine.Length, "\" +");
int indentSize = textEditorData.CaretOffset - line.Offset;
var insertedText = prevLine.GetIndentation (textEditorData) + (trimmedPreviousLine.StartsWith ("\"", StringComparison.Ordinal) ? "" : "\t") + "\"";
textEditorData.ReplaceText (line.Offset, indentSize, insertedText);
return true;
}
}
return false;
}
示例2: GetDiffPaths
Tuple<List<Cairo.Rectangle>, List<Cairo.Rectangle>> GetDiffPaths (List<Mono.TextEditor.Utils.Hunk> diff, TextEditor editor, Hunk hunk)
{
if (!diffCache.ContainsKey (diff))
diffCache[diff] = new Dictionary<Hunk, Tuple<List<Cairo.Rectangle>, List<Cairo.Rectangle>>> ();
var pathCache = diffCache[diff];
Tuple<List<Cairo.Rectangle>, List<Cairo.Rectangle>> result;
if (pathCache.TryGetValue (hunk, out result))
return result;
var words = BreakTextInWords (editor, hunk.RemoveStart, hunk.Removed);
var cmpWords = BreakTextInWords (MainEditor, hunk.InsertStart, hunk.Inserted);
var wordDiff = new List<Hunk> (Diff.GetDiff (words.Select (w => editor.GetTextAt (w)).ToArray (),
cmpWords.Select (w => MainEditor.GetTextAt (w)).ToArray ()));
result = Tuple.Create (CalculateChunkPath (editor, wordDiff, words, true),
CalculateChunkPath (MainEditor, wordDiff, cmpWords, false));
pathCache[hunk] = result;
return result;
}
示例3: DuplicateCurrentLine
public static void DuplicateCurrentLine (TextEditor textEditor)
{
// Code from Mono.TextEditor.MiscActions.DuplicateLine
using (var undoGroup = textEditor.OpenUndoGroup ()) {
if (textEditor.IsSomethingSelected) {
var selectedText = textEditor.SelectedText;
textEditor.ClearSelection ();
textEditor.InsertAtCaret (selectedText);
} else {
var line = textEditor.GetLine (textEditor.CaretLine);
if (line == null)
return;
textEditor.InsertText (line.Offset, textEditor.GetTextAt (line.SegmentIncludingDelimiter));
}
}
}