本文整理汇总了C#中TextEditor.GetVirtualIndentationColumn方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor.GetVirtualIndentationColumn方法的具体用法?C# TextEditor.GetVirtualIndentationColumn怎么用?C# TextEditor.GetVirtualIndentationColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextEditor
的用法示例。
在下文中一共展示了TextEditor.GetVirtualIndentationColumn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Format
static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, TextEditor editor, DocumentContext context, int startOffset, int endOffset, bool exact, bool formatLastStatementOnly = false, OptionSet optionSet = null)
{
TextSpan span;
if (exact) {
span = new TextSpan (startOffset, endOffset - startOffset);
} else {
span = new TextSpan (0, endOffset);
}
var analysisDocument = context.AnalysisDocument;
if (analysisDocument == null)
return;
using (var undo = editor.OpenUndoGroup (/*OperationType.Format*/)) {
try {
var syntaxTree = analysisDocument.GetSyntaxTreeAsync ().Result;
if (formatLastStatementOnly) {
var root = syntaxTree.GetRoot ();
var token = root.FindToken (endOffset);
var tokens = ICSharpCode.NRefactory6.CSharp.FormattingRangeHelper.FindAppropriateRange (token);
if (tokens.HasValue) {
span = new TextSpan (tokens.Value.Item1.SpanStart, tokens.Value.Item2.Span.End - tokens.Value.Item1.SpanStart);
} else {
var parent = token.Parent;
if (parent != null)
span = parent.FullSpan;
}
}
if (optionSet == null) {
var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
var textPolicy = policyParent.Get<TextStylePolicy> (mimeTypeChain);
optionSet = policy.CreateOptions (textPolicy);
}
var doc = Formatter.FormatAsync (analysisDocument, span, optionSet).Result;
var newTree = doc.GetSyntaxTreeAsync ().Result;
var caretOffset = editor.CaretOffset;
int delta = 0;
foreach (var change in newTree.GetChanges (syntaxTree)) {
if (!exact && change.Span.Start + delta >= caretOffset)
continue;
var newText = change.NewText;
editor.ReplaceText (delta + change.Span.Start, change.Span.Length, newText);
delta = delta - change.Span.Length + newText.Length;
}
if (startOffset < caretOffset) {
var caretEndOffset = caretOffset + delta;
if (0 <= caretEndOffset && caretEndOffset < editor.Length)
editor.CaretOffset = caretEndOffset;
if (editor.CaretColumn == 1) {
if (editor.CaretLine > 1 && editor.GetLine (editor.CaretLine - 1).Length == 0)
editor.CaretLine--;
editor.CaretColumn = editor.GetVirtualIndentationColumn (editor.CaretLine);
}
}
} catch (Exception e) {
LoggingService.LogError ("Error in on the fly formatter", e);
}
}
}