本文整理汇总了C#中SnapshotSpan.Intersection方法的典型用法代码示例。如果您正苦于以下问题:C# SnapshotSpan.Intersection方法的具体用法?C# SnapshotSpan.Intersection怎么用?C# SnapshotSpan.Intersection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SnapshotSpan
的用法示例。
在下文中一共展示了SnapshotSpan.Intersection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassifyToken
private ClassificationSpan ClassifyToken(SnapshotSpan span, TokenInfo token, int lineNumber)
{
IClassificationType classification = null;
if (token.Category == TokenCategory.Operator) {
if (token.Trigger == TokenTriggers.MemberSelect) {
classification = _provider.DotClassification;
}
} else if (token.Category == TokenCategory.Grouping) {
if ((token.Trigger & TokenTriggers.MatchBraces) != 0) {
classification = _provider.GroupingClassification;
}
} else if (token.Category == TokenCategory.Delimiter) {
if (token.Trigger == TokenTriggers.ParameterNext) {
classification = _provider.CommaClassification;
}
}
if (classification == null) {
CategoryMap.TryGetValue(token.Category, out classification);
}
if (classification != null) {
var tokenSpan = SnapshotSpanToSpan(span.Snapshot, token, lineNumber);
var intersection = span.Intersection(tokenSpan);
if (intersection != null && intersection.Value.Length > 0 ||
(span.Length == 0 && tokenSpan.Contains(span.Start))) { // handle zero-length spans which Intersect and Overlap won't return true on ever.
return new ClassificationSpan(new SnapshotSpan(span.Snapshot, tokenSpan), classification);
}
}
return null;
}
示例2: GetClassificationSpans
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{
var results = new List<ClassificationSpan>();
var artifacts = artifactsGetter();
// In case the span starts in the middle
// of an HTML code block, we must always
// start from the previous artifact.
int thisArtifact = artifacts.GetLastItemBeforeOrAtPosition(span.Start);
// For each artifact, classify the artifact and
// the plain text after it. If the span starts
// before the first artifact, the 1st iteration
// will classify the leading text only.
while (thisArtifact < artifacts.Count)
{
// If the span starts before the first artifact, thisArtifact will be negative.
if (thisArtifact >= 0)
results.AddRange(ClassifyArtifacts(span.Snapshot, artifacts, ref thisArtifact));
int plainStart = thisArtifact < 0 ? 0 : artifacts[thisArtifact].End;
thisArtifact++;
int plainEnd = thisArtifact == artifacts.Count ? span.Snapshot.Length : artifacts[thisArtifact].Start;
// If artifacts become inconsistent, don't choke
if (plainEnd <= plainStart)
continue;
// Chop off any part before or after the span being classified
var plainSpan = span.Intersection(Span.FromBounds(plainStart, plainEnd));
// If there was no intersection, we've passed the target span and can stop.
if (plainSpan == null) break;
results.AddRange(ClassifyPlainSpan(plainSpan.Value));
}
return results;
}
示例3: ClassifyToken
private ClassificationSpan ClassifyToken(SnapshotSpan span, TokenInfo token, int lineNumber)
{
IClassificationType classification = null;
if (token.Category == TokenCategory.Operator) {
if (token.Trigger == TokenTriggers.MemberSelect) {
classification = _provider.DotClassification;
}
} else if (token.Category == TokenCategory.Grouping) {
if (token.Trigger == (TokenTriggers.MatchBraces | TokenTriggers.ParameterStart)) {
classification = _provider.OpenGroupingClassification;
} else if (token.Trigger == (TokenTriggers.MatchBraces | TokenTriggers.ParameterEnd)) {
classification = _provider.CloseGroupingClassification;
}
} else if (token.Category == TokenCategory.Delimiter) {
if (token.Trigger == TokenTriggers.ParameterNext) {
classification = _provider.CommaClassification;
}
}
if (classification == null) {
CategoryMap.TryGetValue(token.Category, out classification);
}
if (classification != null) {
var line = span.Snapshot.GetLineFromLineNumber(lineNumber);
var index = line.Start.Position + token.SourceSpan.Start.Column - 1;
var tokenSpan = new Span(index, token.SourceSpan.Length);
var intersection = span.Intersection(tokenSpan);
if (intersection != null && intersection.Value.Length > 0) {
return new ClassificationSpan(new SnapshotSpan(span.Snapshot, tokenSpan), classification);
}
}
return null;
}
示例4: Intersects
bool Intersects(SnapshotSpan fullSpan, ITextViewLine line, Rect rect) {
var span = fullSpan.Intersection(line.ExtentIncludingLineBreak);
if (span == null || span.Value.Length == 0)
return false;
var start = line.GetExtendedCharacterBounds(span.Value.Start);
var end = line.GetExtendedCharacterBounds(span.Value.End - 1);
double left = Math.Min(start.Left, end.Left) - wpfTextView.ViewportLeft;
double top = Math.Min(start.Top, end.Top) - wpfTextView.ViewportTop;
double right = Math.Max(start.Right, end.Right) - wpfTextView.ViewportLeft;
double bottom = Math.Max(start.Bottom, end.Bottom) - wpfTextView.ViewportTop;
bool b = left <= right && top <= bottom;
Debug.Assert(b);
if (!b)
return false;
var r = new Rect(left, top, right - left, bottom - top);
return r.IntersectsWith(rect);
}
示例5: GetClassificationSpan
private static ClassificationSpan GetClassificationSpan(SnapshotSpan span, TokenInfo token, int lineNumber, IClassificationType classification) {
var tokenSpan = SnapshotSpanToSpan(span.Snapshot, token, lineNumber);
var intersection = span.Intersection(tokenSpan);
if (intersection != null && intersection.Value.Length > 0 ||
(span.Length == 0 && tokenSpan.Contains(span.Start))) { // handle zero-length spans which Intersect and Overlap won't return true on ever.
return new ClassificationSpan(new SnapshotSpan(span.Snapshot, tokenSpan), classification);
}
return null;
}
示例6: AddClassifications
/// <summary>
/// Adds classification spans to the given collection.
/// Scans a contiguous sub-<paramref name="span"/> of a larger code span which starts at <paramref name="codeStartLine"/>.
/// </summary>
private void AddClassifications(JSScanner JSScanner, List<ClassificationSpan> classifications, SnapshotSpan span) {
Debug.Assert(span.Length > 0);
var snapshot = span.Snapshot;
int firstLine = snapshot.GetLineNumberFromPosition(span.Start);
int lastLine = snapshot.GetLineNumberFromPosition(span.End - 1);
Contract.Assert(firstLine >= 0);
_tokenCache.EnsureCapacity(snapshot.LineCount);
// find the closest line preceding firstLine for which we know categorizer state, stop at the codeStartLine:
LineTokenization lineTokenization;
int currentLine = _tokenCache.IndexOfPreviousTokenization(firstLine, 0, out lineTokenization) + 1;
object state = lineTokenization.State;
// track the previous 2 tokens to adjust our classifications of keywords
// when they shouldn't be displayed as keywords...
TokenInfoWithLine? prevToken = null, prevPrevToken = null;
// initialize the previous tokens so we can handle things like:
// foo.
// get()
// even if we're called on the line for get()
int prevLine = currentLine - 1;
while (prevLine >= 0 && prevToken == null) {
LineTokenization prevLineTokenization = GetPreviousTokenization(JSScanner, snapshot, firstLine, prevLine);
for (int i = prevLineTokenization.Tokens.Length - 1; i >= 0 && prevToken == null; i--) {
var tempToken = prevLineTokenization.Tokens[i];
if (IsValidPreviousToken(ref tempToken)) {
prevToken = prevPrevToken;
prevPrevToken = new TokenInfoWithLine() { TokenInfo = tempToken, Line = prevLine };
}
}
prevLine--;
}
while (currentLine <= lastLine) {
if (!_tokenCache.TryGetTokenization(currentLine, out lineTokenization)) {
lineTokenization = TokenizeLine(JSScanner, snapshot, state, currentLine);
_tokenCache[currentLine] = lineTokenization;
}
state = lineTokenization.State;
for (int i = 0; i < lineTokenization.Tokens.Length; i++) {
var token = lineTokenization.Tokens[i];
if (token.Category == TokenCategory.IncompleteMultiLineStringLiteral || token.Category == TokenCategory.Comment) {
IClassificationType type;
switch (token.Category) {
case TokenCategory.IncompleteMultiLineStringLiteral:
type = _provider.StringLiteral;
break;
case TokenCategory.Comment:
type = _provider.Comment;
break;
default:
type = null;
break;
}
Debug.Assert(type != null, "We should have a defined ClassificationType for every token.");
// we need to walk backwards to find the start of this multi-line string...
TokenInfo startToken = token;
int validPrevLine;
int length = startToken.SourceSpan.Length;
if (i == 0) {
length += GetLeadingMultiLineTokens(JSScanner, snapshot, token.Category, firstLine, currentLine, out validPrevLine, ref startToken);
} else {
validPrevLine = currentLine;
}
if (i == lineTokenization.Tokens.Length - 1) {
length += GetTrailingMultiLineTokens(JSScanner, snapshot, token.Category, currentLine, state);
}
var tokenSpan = new Span(SnapshotSpanToSpan(snapshot, startToken, validPrevLine).Start, length);
var intersection = span.Intersection(tokenSpan);
if ((intersection != null && intersection.Value.Length > 0) ||
(span.Length == 0 && tokenSpan.Contains(span.Start)) // handle zero-length spans
) {
classifications.Add(new ClassificationSpan(new SnapshotSpan(snapshot, tokenSpan), type));
}
} else {
ClassificationSpan classification = null;
if (token.Category == TokenCategory.Keyword) {
// check and see if we're not really a keyword...
if (IsKeywordInIdentifierContext(snapshot, prevToken, prevPrevToken, new TokenInfoWithLine() { TokenInfo = token, Line = currentLine })) {
classification = GetClassificationSpan(
span,
token,
currentLine,
CategoryMap[TokenCategory.Identifier]
//.........这里部分代码省略.........
示例7: Update
void Update(SnapshotSpan span, ref HashSet<ITextViewLine> checkedLines) {
Debug.Assert(span.Snapshot == wpfTextViewHost.TextView.TextSnapshot);
var intersection = span.Intersection(wpfTextViewHost.TextView.TextViewLines.FormattedSpan);
if (intersection == null)
return;
var point = intersection.Value.Start;
while (point <= intersection.Value.End) {
var line = wpfTextViewHost.TextView.TextViewLines.GetTextViewLineContainingBufferPosition(point);
if (line == null)
break;
if (checkedLines == null)
checkedLines = new HashSet<ITextViewLine>();
if (!checkedLines.Contains(line)) {
checkedLines.Add(line);
Update(line);
}
if (line.IsLastDocumentLine())
break;
point = line.GetPointAfterLineBreak();
}
}
示例8: FindAllSingleLineReverse
IEnumerable<FindResult> FindAllSingleLineReverse(ITextSnapshotLine startLine, ITextSnapshotLine endLine, SnapshotSpan searchRange, string searchPattern, FindOptions options, StringComparison stringComparison, string replacePattern) {
Debug.Assert((options & FindOptions.SearchReverse) != 0);
int startLineNumber = startLine.LineNumber;
var snapshot = searchRange.Snapshot;
bool onlyWords = (options & FindOptions.WholeWord) != 0;
var regex = (options & FindOptions.UseRegularExpressions) != 0 ? GetRegex(searchPattern, options) : null;
for (int lineNumber = endLine.LineNumber; lineNumber >= startLineNumber; lineNumber--) {
var line = snapshot.GetLineFromLineNumber(lineNumber);
var range = searchRange.Intersection(line.ExtentIncludingLineBreak);
if (range == null || range.Value.Length == 0)
continue;
var text = range.Value.GetText();
int index = text.Length;
if (regex != null) {
foreach (var res in GetRegexResults(regex, range.Value.Start, text, index, searchPattern, options, replacePattern))
yield return res;
}
else {
while (index > 0) {
index = text.LastIndexOf(searchPattern, index - 1, index, stringComparison);
if (index < 0)
break;
if (!onlyWords || UnicodeUtilities.IsWord(line, range.Value.Start.Position - line.Start.Position + index, searchPattern.Length))
yield return new FindResult(range.Value.Start.Position + index, searchPattern.Length, replacePattern);
index += searchPattern.Length - 1;
}
}
}
}