本文整理汇总了C#中SnapshotPoint类的典型用法代码示例。如果您正苦于以下问题:C# SnapshotPoint类的具体用法?C# SnapshotPoint怎么用?C# SnapshotPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SnapshotPoint类属于命名空间,在下文中一共展示了SnapshotPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateForAllPoints_Line_EndOfSnapshot
public void CreateForAllPoints_Line_EndOfSnapshot()
{
Create("cat", "dog");
var point = new SnapshotPoint(_textBuffer.CurrentSnapshot, _textBuffer.CurrentSnapshot.Length);
var visualSpan = VisualSpan.CreateForAllPoints(VisualKind.Line, point, point);
Assert.AreEqual(1, visualSpan.AsLine().LineRange.LastLineNumber);
}
示例2: GetInvocationSpan
public override Span? GetInvocationSpan(string text, int linePosition, SnapshotPoint position)
{
// If this isn't the beginning of the line, stop immediately.
var quote = text.SkipWhile(Char.IsWhiteSpace).FirstOrDefault();
if (quote != '"' && quote != '\'')
return null;
// If it is, make sure it's also the beginning of a function.
var prevLine = EnumeratePrecedingLineTokens(position).GetEnumerator();
// If we are at the beginning of the file, that is also fine.
if (prevLine.MoveNext())
{
// Check that the previous line contains "function", then
// eventually ") {" followed by the end of the line.
if (!ConsumeToToken(prevLine, "function", "keyword") || !ConsumeToToken(prevLine, ")", "operator"))
return null;
if (!prevLine.MoveNext() || prevLine.Current.Span.GetText() != "{")
return null;
// If there is non-comment code after the function, stop
if (prevLine.MoveNext() && SkipComments(prevLine))
return null;
}
var startIndex = text.TakeWhile(Char.IsWhiteSpace).Count();
var endIndex = linePosition;
// Consume the auto-added close quote, if present.
// If range ends at the end of the line, we cannot
// check this.
if (endIndex < text.Length && text[endIndex] == quote)
endIndex++;
return Span.FromBounds(startIndex, endIndex);
}
示例3: Execute
protected override bool Execute(uint commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
{
if (_broker.IsCompletionActive(TextView) || !IsValidTextBuffer() || !WESettings.GetBoolean(WESettings.Keys.EnableEnterFormat))
return false;
int position = TextView.Caret.Position.BufferPosition.Position;
SnapshotPoint point = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position);
IWpfTextViewLine line = TextView.GetTextViewLineContainingBufferPosition(point);
ElementNode element = null;
AttributeNode attr = null;
_tree.GetPositionElement(position, out element, out attr);
if (element == null ||
_tree.IsDirty ||
element.Parent == null ||
line.End.Position == position || // caret at end of line (TODO: add ignore whitespace logic)
TextView.TextBuffer.CurrentSnapshot.GetText(element.InnerRange.Start, element.InnerRange.Length).Trim().Length == 0)
return false;
UpdateTextBuffer(element, position);
return false;
}
示例4: RemoveToken
/// <summary>
/// Removes a token using the enhanced token stream class.
/// </summary>
/// <param name="sql"></param>
/// <param name="position"></param>
/// <returns></returns>
private CommonTokenStream RemoveToken(string sql, SnapshotPoint snapPos)
{
MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
//ANTLRInputStream input = new ANTLRInputStream(ms);
Version ver = LanguageServiceUtil.GetVersion(LanguageServiceUtil.GetConnection().ServerVersion);
MySQLLexer lexer = new MySQLLexer(input);
lexer.MySqlVersion = ver;
TokenStreamRemovable tokens = new TokenStreamRemovable(lexer);
IToken tr = null;
int position = snapPos.Position;
tokens.Fill();
if (!char.IsWhiteSpace(snapPos.GetChar()))
{
foreach (IToken t in tokens.GetTokens())
{
if ((t.StartIndex <= position) && (t.StopIndex >= position))
{
tr = t;
break;
}
}
tokens.Remove(tr);
}
return tokens;
}
示例5: GetInvocationSpan
public override Span? GetInvocationSpan(string text, int linePosition, SnapshotPoint position)
{
// Find the quoted string inside function call
int startIndex = text.LastIndexOf(FunctionName + "(", linePosition, StringComparison.Ordinal);
if (startIndex < 0)
return null;
startIndex += FunctionName.Length + 1;
startIndex += text.Skip(startIndex).TakeWhile(Char.IsWhiteSpace).Count();
if (linePosition <= startIndex || (text[startIndex] != '"' && text[startIndex] != '\''))
return null;
var endIndex = text.IndexOf(text[startIndex] + ")", startIndex, StringComparison.OrdinalIgnoreCase);
if (endIndex < 0)
endIndex = startIndex + text.Skip(startIndex + 1).TakeWhile(c => Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c) || c == '-' || c == '_').Count() + 1;
else if (linePosition > endIndex + 1)
return null;
// Consume the auto-added close quote, if present.
// If range ends at the end of the line, we cannot
// check this.
if (endIndex < text.Length && text[endIndex] == text[startIndex])
endIndex++;
return Span.FromBounds(startIndex, endIndex);
}
示例6: IsPreceededByEventAddSyntax
/// <summary>
/// Is the provided SnapshotPoint preceded by the '+= SomeEventType(Some_HandlerName' line
/// </summary>
private bool IsPreceededByEventAddSyntax(SnapshotSpan span)
{
// First find the last + character
var snapshot = span.Snapshot;
SnapshotPoint? plusPoint = null;
for (int i = span.Length - 1; i >= 0; i--)
{
var position = span.Start.Position + i;
var point = new SnapshotPoint(snapshot, position);
if (point.GetChar() == '+')
{
plusPoint = point;
break;
}
}
if (plusPoint == null)
{
return false;
}
var eventSpan = new SnapshotSpan(plusPoint.Value, span.End);
var eventText = eventSpan.GetText();
return
s_fullEventSyntaxRegex.IsMatch(eventText) ||
s_shortEventSyntaxRegex.IsMatch(eventText);
}
示例7: FakeTextSnapshotLine
public FakeTextSnapshotLine(ITextSnapshot snapshot, string text, int position, int lineNumber)
{
Snapshot = snapshot;
this._text = text;
LineNumber = lineNumber;
Start = new SnapshotPoint(snapshot, position);
}
示例8: TryCreateSession
public bool TryCreateSession(ITextView textView, SnapshotPoint openingPoint, char openingBrace, char closingBrace, out IBraceCompletionSession session)
{
this.AssertIsForeground();
var textSnapshot = openingPoint.Snapshot;
var document = textSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
var editorSessionFactory = document.GetLanguageService<IEditorBraceCompletionSessionFactory>();
if (editorSessionFactory != null)
{
// Brace completion is (currently) not cancellable.
var cancellationToken = CancellationToken.None;
var editorSession = editorSessionFactory.TryCreateSession(document, openingPoint, openingBrace, cancellationToken);
if (editorSession != null)
{
var undoHistory = _undoManager.GetTextBufferUndoManager(textView.TextBuffer).TextBufferUndoHistory;
session = new BraceCompletionSession(
textView, openingPoint.Snapshot.TextBuffer, openingPoint, openingBrace, closingBrace,
undoHistory, _editorOperationsFactoryService,
editorSession);
return true;
}
}
}
session = null;
return false;
}
示例9: MapUpOrDownToBuffer
public static SnapshotPoint? MapUpOrDownToBuffer(this IBufferGraph bufferGraph, SnapshotPoint point, ITextBuffer targetBuffer)
{
var direction = ClassifyBufferMapDirection(point.Snapshot.TextBuffer, targetBuffer);
switch (direction)
{
case BufferMapDirection.Identity:
return point;
case BufferMapDirection.Down:
{
// TODO (https://github.com/dotnet/roslyn/issues/5281): Remove try-catch.
try
{
return bufferGraph.MapDownToInsertionPoint(point, PointTrackingMode.Positive, s => s == targetBuffer.CurrentSnapshot);
}
catch (ArgumentOutOfRangeException) when (bufferGraph.TopBuffer.ContentType.TypeName == "Interactive Content")
{
// Suppress this to work around DevDiv #144964.
// Note: Other callers might be affected, but this is the narrowest workaround for the observed problems.
// A fix is already being reviewed, so a broader change is not required.
return null;
}
}
case BufferMapDirection.Up:
{
return bufferGraph.MapUpToBuffer(point, PointTrackingMode.Positive, PositionAffinity.Predecessor, targetBuffer);
}
default:
return null;
}
}
示例10: FindOtherBrace
// returns true if brace is actually a brace.
private bool FindOtherBrace(SnapshotPoint possibleBrace, out SnapshotPoint? otherBrace)
{
otherBrace = null;
var rainbow = this.textBuffer.Get<RainbowProvider>();
if ( rainbow == null ) {
return false;
}
if ( !possibleBrace.IsValid() ) {
return false;
}
if ( !rainbow.BraceCache.Language.BraceList.Contains(possibleBrace.GetChar()) ) {
return false;
}
var bracePair = rainbow.BraceCache.GetBracePair(possibleBrace);
if ( bracePair == null ) {
return true;
}
if ( possibleBrace.Position == bracePair.Item1.Position ) {
otherBrace = bracePair.Item2.ToPoint(possibleBrace.Snapshot);
} else {
otherBrace = bracePair.Item1.ToPoint(possibleBrace.Snapshot);
}
return true;
}
示例11: Indent
private bool Indent()
{
int position = _textView.Caret.Position.BufferPosition.Position;
if (position == 0 || position == _textView.TextBuffer.CurrentSnapshot.Length || _textView.Selection.SelectedSpans[0].Length > 0)
return false;
char before = _textView.TextBuffer.CurrentSnapshot.GetText(position - 1, 1)[0];
char after = _textView.TextBuffer.CurrentSnapshot.GetText(position, 1)[0];
if (before == '{' && after == '}')
{
EditorExtensionsPackage.DTE.UndoContext.Open("Smart indent");
_textView.TextBuffer.Insert(position, Environment.NewLine + '\t');
SnapshotPoint point = new SnapshotPoint(_textView.TextBuffer.CurrentSnapshot, position);
_textView.Selection.Select(new SnapshotSpan(point, 4), true);
EditorExtensionsPackage.ExecuteCommand("Edit.FormatSelection");
_textView.Selection.Clear();
SendKeys.Send("{ENTER}");
EditorExtensionsPackage.DTE.UndoContext.Close();
return true;
}
return false;
}
示例12: GetExtentOfWord
public TextExtent GetExtentOfWord(SnapshotPoint currentPosition) {
if (currentPosition.Snapshot?.TextBuffer != textBuffer)
throw new ArgumentException();
if (currentPosition.Position >= currentPosition.Snapshot.Length)
return new TextExtent(new SnapshotSpan(currentPosition, currentPosition), true);
return new TextExtent(new SnapshotSpan(currentPosition, currentPosition + 1), true);
}
示例13: PeekString
public static string PeekString(this ITextSnapshot snapshot, SnapshotPoint point, int length)
{
if (point >= snapshot.Length)
return null;
return new SnapshotSpan(point, Math.Min(length, snapshot.Length - point)).GetText();
}
示例14: GetCurrentScenarioBlock
private ScenarioBlock? GetCurrentScenarioBlock(SnapshotPoint triggerPoint)
{
var parsingResult = gherkinProcessorServices.GetParsingResult(textBuffer);
if (parsingResult == null)
return null;
var triggerLineNumber = triggerPoint.Snapshot.GetLineNumberFromPosition(triggerPoint.Position);
var scenarioInfo = parsingResult.ScenarioEditorInfos.LastOrDefault(si => si.KeywordLine < triggerLineNumber);
if (scenarioInfo == null)
return null;
for (var lineNumer = triggerLineNumber; lineNumer > scenarioInfo.KeywordLine; lineNumer--)
{
StepKeyword? stepKeyword = GetStepKeyword(triggerPoint.Snapshot, lineNumer, parsingResult.LanguageService);
if (stepKeyword != null)
{
var scenarioBlock = stepKeyword.Value.ToScenarioBlock();
if (scenarioBlock != null)
return scenarioBlock;
}
}
return ScenarioBlock.Given;
}
示例15: EndTracking
/// <summary>
/// Restores saved selection
/// </summary>
public override void EndTracking() {
int position = PositionFromTokens(TextBuffer.CurrentSnapshot, _index, _offset);
if (position >= 0) {
PositionAfterChanges = new SnapshotPoint(TextBuffer.CurrentSnapshot, position);
}
MoveToAfterChanges(VirtualSpaces);
}