diff --git a/src/InteractiveWindow/Editor/InteractiveWindow.cs b/src/InteractiveWindow/Editor/InteractiveWindow.cs index ef165e984e3bded61c1347e424a7b1991e2255a4..460227983e9b71d57bc10ab87bdcc41daba5d940 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 2eedc59b67cde003308eaa1a0d10efa80d5c0199..e78e0746c68358af012ccb74dc9ec7e9c8af13b8 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