diff --git a/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts b/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts index 800a79a7554..ce78f7736b8 100644 --- a/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts +++ b/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts @@ -77,7 +77,11 @@ async function handleSessionStream( formatLogEvent(logEvent) ) if (formattedLogEvents.length !== 0) { + //Determine should scroll before adding new lines to doc because adding large + //amount of new lines can push bottom of file out of view before scrolling. + const editorsToScroll = getTextEditorsToScroll(document) await updateTextDocumentWithNewLogEvents(formattedLogEvents, document, session.maxLines) + editorsToScroll.forEach(scrollTextEditorToBottom) } } } @@ -99,6 +103,22 @@ function formatLogEvent(logEvent: LiveTailSessionLogEvent): string { return line } +//Auto scroll visible LiveTail session editors if the end-of-file is in view. +//This allows for newly added log events to stay in view. +function getTextEditorsToScroll(document: vscode.TextDocument): vscode.TextEditor[] { + return vscode.window.visibleTextEditors.filter((editor) => { + if (editor.document !== document) { + return false + } + return editor.visibleRanges[0].contains(new vscode.Position(document.lineCount - 1, 0)) + }) +} + +function scrollTextEditorToBottom(editor: vscode.TextEditor) { + const position = new vscode.Position(Math.max(editor.document.lineCount - 2, 0), 0) + editor.revealRange(new vscode.Range(position, position), vscode.TextEditorRevealType.Default) +} + async function updateTextDocumentWithNewLogEvents( formattedLogEvents: string[], document: vscode.TextDocument,