本文整理汇总了C#中TextEditor.GetCharAt方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.GetCharAt方法的具体用法?C# TextEditor.GetCharAt怎么用?C# TextEditor.GetCharAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor.GetCharAt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CorrectIndentingImplementation
protected override void CorrectIndentingImplementation (PolicyContainer policyParent, TextEditor editor, int line)
{
var lineSegment = editor.GetLine (line);
if (lineSegment == null)
return;
try {
var policy = policyParent.Get<CSharpFormattingPolicy> (MimeType);
var textpolicy = policyParent.Get<TextStylePolicy> (MimeType);
var tracker = new CSharpIndentEngine (policy.CreateOptions (textpolicy));
tracker.Update (IdeApp.Workbench.ActiveDocument.Editor, lineSegment.Offset);
for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.Length; i++) {
tracker.Push (editor.GetCharAt (i));
}
string curIndent = lineSegment.GetIndentation (editor);
int nlwsp = curIndent.Length;
if (!tracker.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.LengthIncludingDelimiter && editor.GetCharAt (lineSegment.Offset + nlwsp) == '*')) {
// Possibly replace the indent
string newIndent = tracker.ThisLineIndent;
if (newIndent != curIndent)
editor.ReplaceText (lineSegment.Offset, nlwsp, newIndent);
}
} catch (Exception e) {
LoggingService.LogError ("Error while indenting", e);
}
}
示例2: TransposeCharacters
public static void TransposeCharacters (TextEditor textEditor)
{
// Code from Mono.TextEditor.MiscActions.TransposeCharacters
if (textEditor.CaretOffset == 0)
return;
var line = textEditor.GetLine (textEditor.CaretLine);
if (line == null)
return;
using (var undoGroup = textEditor.OpenUndoGroup ()) {
int transposeOffset = textEditor.CaretOffset - 1;
char ch;
if (textEditor.CaretColumn == 0) {
var lineAbove = textEditor.GetLine (textEditor.CaretLine - 1);
if (lineAbove.Length == 0 && line.Length == 0)
return;
if (line.Length != 0) {
ch = textEditor.GetCharAt (textEditor.CaretOffset);
textEditor.RemoveText (textEditor.CaretOffset, 1);
textEditor.InsertText (lineAbove.Offset + lineAbove.Length, ch.ToString ());
return;
}
int lastCharOffset = lineAbove.Offset + lineAbove.Length - 1;
ch = textEditor.GetCharAt (lastCharOffset);
textEditor.RemoveText (lastCharOffset, 1);
textEditor.InsertAtCaret (ch.ToString ());
return;
}
int offset = textEditor.CaretOffset;
if (textEditor.CaretColumn >= line.Length + 1) {
offset = line.Offset + line.Length - 1;
transposeOffset = offset - 1;
// case one char in line:
if (transposeOffset < line.Offset) {
var lineAbove = textEditor.GetLine (textEditor.CaretLine - 1);
transposeOffset = lineAbove.Offset + lineAbove.Length;
ch = textEditor.GetCharAt (offset);
textEditor.RemoveText (offset, 1);
textEditor.InsertText (transposeOffset, ch.ToString ());
textEditor.CaretOffset = line.Offset;
return;
}
}
ch = textEditor.GetCharAt (offset);
textEditor.ReplaceText (offset, 1, textEditor.GetCharAt (transposeOffset).ToString ());
textEditor.ReplaceText (transposeOffset, 1, ch.ToString ());
if (textEditor.CaretColumn < line.Length + 1)
textEditor.CaretOffset = offset + 1;
}
}
示例3: CreateErrorMarker
public static IErrorMarker CreateErrorMarker (TextEditor editor, Error info)
{
int offset = editor.LocationToOffset (info.Region.BeginLine, info.Region.BeginColumn);
int endOffset = editor.LocationToOffset (info.Region.EndLine, info.Region.EndColumn);
if (endOffset <= offset) {
endOffset = offset + 1;
while (endOffset < editor.Length && IsIdentifierPart (editor.GetCharAt (endOffset))) {
endOffset++;
}
if (endOffset == offset + 1) {
if (endOffset - 1 < editor.Length) {
var c = editor.GetCharAt (endOffset - 1);
while ((c == '\n' || c == '\r') && endOffset < editor.Length) {
c = editor.GetCharAt (endOffset);
endOffset++;
}
} else {
endOffset = editor.Length;
}
}
}
return editor.TextMarkerFactory.CreateErrorMarker (editor, info, offset, endOffset - offset);
}
示例4: CreateErrorMarker
public static IErrorMarker CreateErrorMarker (TextEditor editor, Error info)
{
int offset = editor.LocationToOffset (info.Region.BeginLine, info.Region.BeginColumn);
int endOffset = editor.LocationToOffset (info.Region.EndLine, info.Region.EndColumn);
if (endOffset < offset) {
endOffset = offset + 1;
while (endOffset < editor.Length && IsIdentifierPart (editor.GetCharAt (endOffset)))
endOffset++;
}
return editor.TextMarkerFactory.CreateErrorMarker (editor, info, offset, endOffset - offset);
}