Skip to content

Commit e3ee3f7

Browse files
author
Keegan Irby
committed
Support autoscrolling
1 parent 76ed8fb commit e3ee3f7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
102124
async function updateTextDocumentWithNewLogEvents(
103125
formattedLogEvents: string[],
104126
document: vscode.TextDocument,

0 commit comments

Comments
 (0)