From 7c8317215fea76dd5806182c96ca064dbeff41f0 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 24 Aug 2015 14:48:40 -0700 Subject: [PATCH] Make BreakLine follow the cursor --- src/InteractiveWindow/Editor/InteractiveWindow.cs | 8 ++------ .../Editor/InteractiveWindow_UIThread.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/InteractiveWindow/Editor/InteractiveWindow.cs b/src/InteractiveWindow/Editor/InteractiveWindow.cs index ef165e984e3..460227983e9 100644 --- a/src/InteractiveWindow/Editor/InteractiveWindow.cs +++ b/src/InteractiveWindow/Editor/InteractiveWindow.cs @@ -662,12 +662,7 @@ private void DeletePreviousCharacter() point.Value.Snapshot.TextBuffer.Delete(new Span(point.Value.Position - characterSize, characterSize)); - UIThread(uiOnly => - { - // scroll to the line being edited: - SnapshotPoint caretPosition = _textView.Caret.Position.BufferPosition; - _textView.ViewScroller.EnsureSpanVisible(new SnapshotSpan(caretPosition.Snapshot, caretPosition, 0)); - }); + UIThread(uiOnly => uiOnly.ScrollToCaret()); } private void CutOrDeleteCurrentLine(bool isCut) @@ -1049,6 +1044,7 @@ private bool HandlePostServicesReturn(bool trySubmit) // insert new line (triggers secondary prompt injection in buffer changed event): _currentLanguageBuffer.Insert(caretPosition, _lineBreakString); IndentCurrentLine(_textView.Caret.Position.BufferPosition); + UIThread(uiOnly => uiOnly.ScrollToCaret()); return true; } diff --git a/src/InteractiveWindow/Editor/InteractiveWindow_UIThread.cs b/src/InteractiveWindow/Editor/InteractiveWindow_UIThread.cs index 2eedc59b67c..e78e0746c68 100644 --- a/src/InteractiveWindow/Editor/InteractiveWindow_UIThread.cs +++ b/src/InteractiveWindow/Editor/InteractiveWindow_UIThread.cs @@ -961,6 +961,14 @@ private void AddLanguageBuffer() // projection buffer update must be the last operation as it might trigger event that accesses prompt line mapping: _window.AppendProjectionSpans(promptSpan, languageSpan); } + + public void ScrollToCaret() + { + var textView = _window._textView; + var caretPosition = textView.Caret.Position.BufferPosition; + var caretSpan = new SnapshotSpan(caretPosition.Snapshot, caretPosition, 0); + textView.ViewScroller.EnsureSpanVisible(caretSpan); + } } internal enum State -- GitLab