本文整理汇总了C#中ITextView.GetSpanInView方法的典型用法代码示例。如果您正苦于以下问题:C# ITextView.GetSpanInView方法的具体用法?C# ITextView.GetSpanInView怎么用?C# ITextView.GetSpanInView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextView
的用法示例。
在下文中一共展示了ITextView.GetSpanInView方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPairExtentsWorker
// Internal for testing purposes
internal static int GetPairExtentsWorker(ITextView textView, Workspace workspace, IBraceMatchingService braceMatcher, int iLine, int iIndex, TextSpan[] pSpan, CancellationToken cancellationToken)
{
pSpan[0].iStartLine = pSpan[0].iEndLine = iLine;
pSpan[0].iStartIndex = pSpan[0].iEndIndex = iIndex;
var pointInViewBuffer = textView.TextSnapshot.GetLineFromLineNumber(iLine).Start + iIndex;
var subjectBuffer = textView.GetBufferContainingCaret();
if (subjectBuffer != null)
{
// PointTrackingMode and PositionAffinity chosen arbitrarily.
var positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Successor);
if (!positionInSubjectBuffer.HasValue)
{
positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Predecessor);
}
if (positionInSubjectBuffer.HasValue)
{
var position = positionInSubjectBuffer.Value;
var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
var matchingSpan = braceMatcher.FindMatchingSpanAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);
if (matchingSpan.HasValue)
{
var resultsInView = textView.GetSpanInView(matchingSpan.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList();
if (resultsInView.Count == 1)
{
var vsTextSpan = resultsInView[0].ToVsTextSpan();
if (matchingSpan.Value.Start < position)
{
pSpan[0].iStartLine = vsTextSpan.iStartLine;
pSpan[0].iStartIndex = vsTextSpan.iStartIndex;
}
else if (matchingSpan.Value.End > position)
{
pSpan[0].iEndLine = vsTextSpan.iEndLine;
pSpan[0].iEndIndex = vsTextSpan.iEndIndex;
}
}
}
}
}
}
return VSConstants.S_OK;
}
示例2: GetPairExtentsWorker
// Internal for testing purposes
internal static int GetPairExtentsWorker(ITextView textView, Workspace workspace, IBraceMatchingService braceMatcher, int iLine, int iIndex, TextSpan[] pSpan, bool extendSelection, CancellationToken cancellationToken)
{
pSpan[0].iStartLine = pSpan[0].iEndLine = iLine;
pSpan[0].iStartIndex = pSpan[0].iEndIndex = iIndex;
var pointInViewBuffer = textView.TextSnapshot.GetLineFromLineNumber(iLine).Start + iIndex;
var subjectBuffer = textView.GetBufferContainingCaret();
if (subjectBuffer != null)
{
// PointTrackingMode and PositionAffinity chosen arbitrarily.
var positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Successor);
if (!positionInSubjectBuffer.HasValue)
{
positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Predecessor);
}
if (positionInSubjectBuffer.HasValue)
{
var position = positionInSubjectBuffer.Value;
var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
var matchingSpan = braceMatcher.FindMatchingSpanAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);
if (matchingSpan.HasValue)
{
var resultsInView = textView.GetSpanInView(matchingSpan.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList();
if (resultsInView.Count == 1)
{
var vsTextSpan = resultsInView[0].ToVsTextSpan();
// caret is at close parenthesis
if (matchingSpan.Value.Start < position)
{
pSpan[0].iStartLine = vsTextSpan.iStartLine;
pSpan[0].iStartIndex = vsTextSpan.iStartIndex;
// For text selection using goto matching brace, tweak spans to suit the VS editor's behavior.
// The vs editor sets selection for GotoBraceExt (Ctrl + Shift + ]) like so :
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// if (fExtendSelection)
// {
// textSpan.iEndIndex++;
// this.SetSelection(textSpan.iStartLine, textSpan.iStartIndex, textSpan.iEndLine, textSpan.iEndIndex);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Notice a couple of things: it arbitrarily increments EndIndex by 1 and does nothing similar for StartIndex.
// So, if we're extending selection:
// case a: set EndIndex to left of closing parenthesis -- ^}
// this adjustment is for any of the four cases where caret could be. left or right of open or close parenthesis -- ^{^ ^}^
// case b: set StartIndex to left of opening parenthesis -- ^{
// this adjustment is for cases where caret was originally to the right of the open parenthesis -- {^ }
// if selecting, adjust end position by using the matching opening span that we just computed.
if (extendSelection)
{
// case a.
var closingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.Start, cancellationToken).WaitAndGetResult(cancellationToken);
var vsClosingSpans = textView.GetSpanInView(closingSpans.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList().First().ToVsTextSpan();
pSpan[0].iEndIndex = vsClosingSpans.iStartIndex;
}
}
else if (matchingSpan.Value.End > position) // caret is at open parenthesis
{
pSpan[0].iEndLine = vsTextSpan.iEndLine;
pSpan[0].iEndIndex = vsTextSpan.iEndIndex;
// if selecting, adjust start position by using the matching closing span that we computed
if (extendSelection)
{
// case a.
pSpan[0].iEndIndex = vsTextSpan.iStartIndex;
// case b.
var openingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.End, cancellationToken).WaitAndGetResult(cancellationToken);
var vsOpeningSpans = textView.GetSpanInView(openingSpans.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList().First().ToVsTextSpan();
pSpan[0].iStartIndex = vsOpeningSpans.iStartIndex;
}
}
}
}
}
}
}
return VSConstants.S_OK;
}