fix: terminal now auto-scrolls on output (was missing AfterViewChecked)

This commit is contained in:
Butterfly Dev 2026-04-07 04:00:51 +00:00
parent f3da41da01
commit b7d6c950cf

View File

@ -1,4 +1,4 @@
import { Component, ElementRef, ViewChild, AfterViewInit, signal } from '@angular/core'; import { Component, ElementRef, ViewChild, AfterViewInit, AfterViewChecked, signal } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@Component({ @Component({
@ -8,7 +8,7 @@ import { CommonModule } from '@angular/common';
templateUrl: './terminal.component.html', templateUrl: './terminal.component.html',
styleUrl: './terminal.component.scss', styleUrl: './terminal.component.scss',
}) })
export class TerminalComponent implements AfterViewInit { export class TerminalComponent implements AfterViewInit, AfterViewChecked {
@ViewChild('terminalBody') terminalBody!: ElementRef<HTMLDivElement>; @ViewChild('terminalBody') terminalBody!: ElementRef<HTMLDivElement>;
@ViewChild('termInput') termInput!: ElementRef<HTMLInputElement>; @ViewChild('termInput') termInput!: ElementRef<HTMLInputElement>;
@ -96,6 +96,11 @@ export class TerminalComponent implements AfterViewInit {
this.lines.update((l) => [...l, text]); this.lines.update((l) => [...l, text]);
} }
/** Auto-scroll to bottom whenever the view updates. */
ngAfterViewChecked(): void {
this.scrollToBottom();
}
/** Focus the input when the terminal is clicked. */ /** Focus the input when the terminal is clicked. */
onClick(): void { onClick(): void {
this.termInput?.nativeElement.focus(); this.termInput?.nativeElement.focus();