Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone has a two visible editors, one on the left and one on the right like:

____________________________________________________
|                      |                           |
| first editor         |       second editor       |
|                      |                           |
____________________________________________________

does that mean both of them will scroll?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! they'd both be considered visible and able to be scrolled if at EOF. If one isn't at EOF, and the other is, then only one would be scrolled.

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,
Expand Down
Loading