本文整理汇总了C#中ITextSnapshotLine.GetFirstNonWhitespacePosition方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSnapshotLine.GetFirstNonWhitespacePosition方法的具体用法?C# ITextSnapshotLine.GetFirstNonWhitespacePosition怎么用?C# ITextSnapshotLine.GetFirstNonWhitespacePosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextSnapshotLine
的用法示例。
在下文中一共展示了ITextSnapshotLine.GetFirstNonWhitespacePosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIndentationOfLine
protected IndentationResult GetIndentationOfLine(ITextSnapshotLine lineToMatch, int addedSpaces)
{
var firstNonWhitespace = lineToMatch.GetFirstNonWhitespacePosition();
firstNonWhitespace = firstNonWhitespace ?? lineToMatch.End.Position;
return GetIndentationOfPosition(new SnapshotPoint(lineToMatch.Snapshot, firstNonWhitespace.Value), addedSpaces);
}
示例2: ShouldUseSmartTokenFormatterInsteadOfIndenter
public static bool ShouldUseSmartTokenFormatterInsteadOfIndenter(
IEnumerable<IFormattingRule> formattingRules,
CompilationUnitSyntax root,
ITextSnapshotLine line,
OptionSet optionSet,
CancellationToken cancellationToken)
{
Contract.ThrowIfNull(formattingRules);
Contract.ThrowIfNull(root);
Contract.ThrowIfNull(line);
if (optionSet.GetOption(FormattingOptions.SmartIndent, LanguageNames.CSharp) != FormattingOptions.IndentStyle.Smart)
{
return false;
}
var firstNonWhitespacePosition = line.GetFirstNonWhitespacePosition();
if (!firstNonWhitespacePosition.HasValue)
{
return false;
}
var token = root.FindToken(firstNonWhitespacePosition.Value);
if (token.IsKind(SyntaxKind.None) ||
token.SpanStart != firstNonWhitespacePosition)
{
return false;
}
// first see whether there is a line operation for current token
var previousToken = token.GetPreviousToken(includeZeroWidth: true);
// only use smart token formatter when we have two visible tokens.
if (previousToken.Kind() == SyntaxKind.None || previousToken.IsMissing)
{
return false;
}
var lineOperation = FormattingOperations.GetAdjustNewLinesOperation(formattingRules, previousToken, token, optionSet);
if (lineOperation != null && lineOperation.Option != AdjustNewLinesOption.ForceLinesIfOnSingleLine)
{
return true;
}
// no indentation operation, nothing to do for smart token formatter
return false;
}