private void OnPostTypeChar(char typedCharacter) { // When language autoformats, like JS, caret may be in a very different // place by now. Check if store caret position still makes sense and // if not, reacquire it. In contained language scenario // current caret position may be beyond projection boundary like when // typing at the end of onclick="return foo(". if (!MarkdownEditorPackage.Options.EnableTypeThrough) { return; } char completionCharacter = GetCompletionCharacter(typedCharacter); if (completionCharacter != '\0') { var viewCaretPosition = _textView.Caret.Position.BufferPosition; _processing = true; var bufferCaretPosition = GetCaretPositionInBuffer(); if (bufferCaretPosition.HasValue) { _caretPosition = bufferCaretPosition.Value; } else if (viewCaretPosition.Position == _textView.TextBuffer.CurrentSnapshot.Length) { _caretPosition = _textBuffer.CurrentSnapshot.Length; } if (_caretPosition > 0) { if (CanComplete(_textBuffer, _caretPosition - 1)) { ProvisionalText.IgnoreChange = true; _textView.TextBuffer.Replace(new Span(viewCaretPosition, 0), completionCharacter.ToString()); ProvisionalText.IgnoreChange = false; _textView.Caret.MoveTo(new SnapshotPoint(_textView.TextBuffer.CurrentSnapshot, viewCaretPosition)); var provisionalText = new ProvisionalText(_textView, new Span(viewCaretPosition - 1, 2)); provisionalText.OnClose += OnCloseProvisionalText; _provisionalTexts.Add(provisionalText); } } } _processing = false; }
private ProvisionalText GetInnerProvisionalText() { int minLength = Int32.MaxValue; ProvisionalText innerText = null; foreach (var pt in _provisionalTexts) { if (pt.CurrentSpan.Length < minLength) { minLength = pt.CurrentSpan.Length; innerText = pt; } } return(innerText); }