@@ -77,7 +77,11 @@ async function handleSessionStream(
7777 formatLogEvent ( logEvent )
7878 )
7979 if ( formattedLogEvents . length !== 0 ) {
80+ //Determine should scroll before adding new lines to doc because adding large
81+ //amount of new lines can push bottom of file out of view before scrolling.
82+ const editorsToScroll = getTextEditorsToScroll ( document )
8083 await updateTextDocumentWithNewLogEvents ( formattedLogEvents , document , session . maxLines )
84+ editorsToScroll . forEach ( scrollTextEditorToBottom )
8185 }
8286 }
8387 }
@@ -99,6 +103,24 @@ function formatLogEvent(logEvent: LiveTailSessionLogEvent): string {
99103 return line
100104}
101105
106+ //Auto scroll visible LiveTail session editors if the end-of-file is in view.
107+ //This allows for newly added log events to stay in view.
108+ function getTextEditorsToScroll ( document : vscode . TextDocument ) : vscode . TextEditor [ ] {
109+ return vscode . window . visibleTextEditors . filter ( ( editor ) => {
110+ const isEditorForSession = editor . document === document
111+ if ( ! isEditorForSession ) {
112+ return false
113+ }
114+ return editor . visibleRanges [ 0 ] . contains ( new vscode . Position ( document . lineCount - 1 , 0 ) )
115+ } )
116+ }
117+
118+ function scrollTextEditorToBottom ( editor : vscode . TextEditor ) {
119+ const topPosition = new vscode . Position ( Math . max ( editor . document . lineCount - 2 , 0 ) , 0 )
120+ const bottomPosition = new vscode . Position ( Math . max ( editor . document . lineCount - 2 , 0 ) , 0 )
121+ editor . revealRange ( new vscode . Range ( topPosition , bottomPosition ) , vscode . TextEditorRevealType . Default )
122+ }
123+
102124async function updateTextDocumentWithNewLogEvents (
103125 formattedLogEvents : string [ ] ,
104126 document : vscode . TextDocument ,
0 commit comments