From e3ee3f7556b03f6c939aab3cda0c7608590a59ef Mon Sep 17 00:00:00 2001 From: Keegan Irby Date: Thu, 24 Oct 2024 11:04:46 -0700 Subject: [PATCH 1/3] Support autoscrolling --- .../cloudWatchLogs/commands/tailLogGroup.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts b/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts index 800a79a7554..5e4a8471d10 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,24 @@ 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) => { + const isEditorForSession = editor.document === document + if (!isEditorForSession) { + return false + } + return editor.visibleRanges[0].contains(new vscode.Position(document.lineCount - 1, 0)) + }) +} + +function scrollTextEditorToBottom(editor: vscode.TextEditor) { + const topPosition = new vscode.Position(Math.max(editor.document.lineCount - 2, 0), 0) + const bottomPosition = new vscode.Position(Math.max(editor.document.lineCount - 2, 0), 0) + editor.revealRange(new vscode.Range(topPosition, bottomPosition), vscode.TextEditorRevealType.Default) +} + async function updateTextDocumentWithNewLogEvents( formattedLogEvents: string[], document: vscode.TextDocument, From 008746d5942d3f574cb86b25066fa10940e5ca4e Mon Sep 17 00:00:00 2001 From: Keegan Irby Date: Thu, 24 Oct 2024 13:05:47 -0700 Subject: [PATCH 2/3] Remove redundant position variable --- .../src/awsService/cloudWatchLogs/commands/tailLogGroup.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts b/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts index 5e4a8471d10..af3ca3fbb2c 100644 --- a/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts +++ b/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts @@ -116,9 +116,8 @@ function getTextEditorsToScroll(document: vscode.TextDocument): vscode.TextEdito } function scrollTextEditorToBottom(editor: vscode.TextEditor) { - const topPosition = new vscode.Position(Math.max(editor.document.lineCount - 2, 0), 0) - const bottomPosition = new vscode.Position(Math.max(editor.document.lineCount - 2, 0), 0) - editor.revealRange(new vscode.Range(topPosition, bottomPosition), vscode.TextEditorRevealType.Default) + 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( From 9f28e4c7b2766496af745bac67831c1c5a19e372 Mon Sep 17 00:00:00 2001 From: Keegan Irby Date: Fri, 25 Oct 2024 09:32:10 -0700 Subject: [PATCH 3/3] Remove redundant isEditorForSession variable --- .../src/awsService/cloudWatchLogs/commands/tailLogGroup.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts b/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts index af3ca3fbb2c..ce78f7736b8 100644 --- a/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts +++ b/packages/core/src/awsService/cloudWatchLogs/commands/tailLogGroup.ts @@ -107,8 +107,7 @@ function formatLogEvent(logEvent: LiveTailSessionLogEvent): string { //This allows for newly added log events to stay in view. function getTextEditorsToScroll(document: vscode.TextDocument): vscode.TextEditor[] { return vscode.window.visibleTextEditors.filter((editor) => { - const isEditorForSession = editor.document === document - if (!isEditorForSession) { + if (editor.document !== document) { return false } return editor.visibleRanges[0].contains(new vscode.Position(document.lineCount - 1, 0))