Skip to content

Commit 279562d

Browse files
authored
fix: scrolling! (#28)
1 parent ffb79fd commit 279562d

File tree

3 files changed

+33
-83
lines changed

3 files changed

+33
-83
lines changed

lib/widgets/list.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,9 @@ class List extends ScrollableBox {
527527
}
528528
}
529529

530-
// Basic scrollTo implementation for list functionality
530+
// Use parent ScrollableBox scrollTo implementation
531531
scrollTo(offset: number, always?: boolean): any {
532-
// For now, just a stub implementation
533-
// This should be replaced with proper scrolling logic
534-
return;
532+
return super.scrollTo(offset, always);
535533
}
536534

537535
select = (index: any): void => {

lib/widgets/terminal.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ class Terminal extends Box {
115115
}
116116

117117
this.pty.onData(() => {
118+
// Auto-scroll to bottom when new content arrives
119+
if (this.term && typeof this.term.scrollToBottom === 'function') {
120+
this.term.scrollToBottom();
121+
}
118122
setTimeout(() => this.screen.render(), 16);
119123
});
120124

@@ -186,11 +190,13 @@ class Terminal extends Box {
186190
if (xi >= xl || yi >= yl) return ret;
187191

188192
const buf = this.term.buffer.active;
193+
const viewportY = buf.viewportY || 0; // Get the current scroll position
194+
189195
for (var y = yi; y < yl; y++) {
190196
var line = this.screen.lines[y];
191197
if (!line) continue;
192198

193-
var bufferY = y - yi;
199+
var bufferY = y - yi + viewportY; // Account for scroll position
194200
var bufferLine = buf.getLine(bufferY);
195201
if (!bufferLine) continue;
196202

@@ -264,6 +270,30 @@ class Terminal extends Box {
264270
}
265271
}
266272

273+
scrollTo(line: number): void {
274+
if (this.term && typeof this.term.scrollToLine === 'function') {
275+
this.term.scrollToLine(line);
276+
}
277+
}
278+
279+
scroll(offset: number): void {
280+
if (this.term && typeof this.term.scrollLines === 'function') {
281+
this.term.scrollLines(offset);
282+
}
283+
}
284+
285+
scrollToTop(): void {
286+
if (this.term && typeof this.term.scrollToTop === 'function') {
287+
this.term.scrollToTop();
288+
}
289+
}
290+
291+
scrollToBottom(): void {
292+
if (this.term && typeof this.term.scrollToBottom === 'function') {
293+
this.term.scrollToBottom();
294+
}
295+
}
296+
267297
kill() {
268298
if (this.pty) this.pty.kill();
269299
if (this.term) this.term.dispose();

test/simple-list-test.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)