internal void CheckOverType(IBraceCompletionSession session, bool allowOverType = true) { var preClosingPoint = session.ClosingPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot); Assert.Equal(session.ClosingBrace, preClosingPoint.Subtract(1).GetChar()); bool handled; session.PreOverType(out handled); if (!handled) { session.PostOverType(); } var postClosingPoint = session.ClosingPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot); Assert.Equal(postClosingPoint.Subtract(1).GetChar(), session.ClosingBrace); var caret = session.TextView.GetCaretPoint(session.SubjectBuffer).Value; if (allowOverType) { Assert.Equal(postClosingPoint.Position, caret.Position); } else { Assert.True(caret.Position < postClosingPoint.Position); } }
public void PreTypeChar(char character, out bool handledCommand) { bool handled = false; bool hasSelection = HasSelection; Debug.Assert(_postSession == null, "_postSession should have been cleared"); // give the existing session a chance to handle the character first if (_stack.TopSession != null && !hasSelection) { IBraceCompletionSession session = _stack.TopSession; // check for an existing session first _guardedOperations.CallExtensionPoint(errorSource: session, () => { if (session.ClosingBrace.Equals(character) && IsCaretOnBuffer(session.SubjectBuffer)) { session.PreOverType(out handled); if (!handled) { _postSession = session; } } }); } handledCommand = handled; // otherwise check if this starts a new session if (_postSession == null && !handled && Enabled && !hasSelection && _sessionAggregator.OpeningBraces.IndexOf(character) > -1 && !HasForwardTypingOnLine) { SnapshotPoint?openingPoint = _textView.Caret.Position.Point.GetInsertionPoint((b => _sessionAggregator.IsSupportedContentType(b.ContentType, character))); if (openingPoint.HasValue) { IBraceCompletionSession session = null; if (_sessionAggregator.TryCreateSession(_textView, openingPoint.Value, character, out session)) { // add the session after the current keystroke completes _waitingSession = session; _waitingSessionOpeningPoint = openingPoint; } } } }
internal void CheckOverType(IBraceCompletionSession session, bool allowOverType = true) { var preClosingPoint = session.ClosingPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot); Assert.Equal(preClosingPoint.Subtract(1).GetChar(), session.ClosingBrace); bool handled; session.PreOverType(out handled); if (!handled) { session.PostOverType(); } var postClosingPoint = session.ClosingPoint.GetPoint(session.SubjectBuffer.CurrentSnapshot); Assert.Equal(postClosingPoint.Subtract(1).GetChar(), session.ClosingBrace); var caret = session.TextView.GetCaretPoint(session.SubjectBuffer).Value; if (allowOverType) { Assert.Equal(postClosingPoint.Position, caret.Position); } else { Assert.True(caret.Position < postClosingPoint.Position); } }