diff --git a/desktop/src/app/components/apps/terminal/terminal.component.ts b/desktop/src/app/components/apps/terminal/terminal.component.ts index db52354..2b471fe 100644 --- a/desktop/src/app/components/apps/terminal/terminal.component.ts +++ b/desktop/src/app/components/apps/terminal/terminal.component.ts @@ -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'; @Component({ @@ -8,7 +8,7 @@ import { CommonModule } from '@angular/common'; templateUrl: './terminal.component.html', styleUrl: './terminal.component.scss', }) -export class TerminalComponent implements AfterViewInit { +export class TerminalComponent implements AfterViewInit, AfterViewChecked { @ViewChild('terminalBody') terminalBody!: ElementRef; @ViewChild('termInput') termInput!: ElementRef; @@ -96,6 +96,11 @@ export class TerminalComponent implements AfterViewInit { 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. */ onClick(): void { this.termInput?.nativeElement.focus();