-
Notifications
You must be signed in to change notification settings - Fork 738
feat(cwl): Support autoscrolling live tail session's visible editors #5857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
jpinkney-aws marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| editor.revealRange(new vscode.Range(topPosition, bottomPosition), vscode.TextEditorRevealType.Default) | ||
| } | ||
|
|
||
| async function updateTextDocumentWithNewLogEvents( | ||
| formattedLogEvents: string[], | ||
| document: vscode.TextDocument, | ||
|
|
||
There was a problem hiding this comment.
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:
does that mean both of them will scroll?
There was a problem hiding this comment.
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.