Skip to content

Commit fb76b25

Browse files
perf(vt100): directly index into visible rows
1 parent 1c49621 commit fb76b25

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

crates/turborepo-vt100/src/grid.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,21 @@ impl Grid {
198198
}
199199

200200
pub fn visible_row(&self, row: u16) -> Option<&crate::row::Row> {
201-
self.visible_rows().nth(usize::from(row))
201+
// The number of rows that are in scrollback before the current screen
202+
let scrollback_rows_before_screen =
203+
self.scrollback.len().saturating_sub(self.scrollback_offset);
204+
// The index for row if it is in the scrollback
205+
let scrollback_idx = scrollback_rows_before_screen + usize::from(row);
206+
// If this is a valid scrollback index, then return that row
207+
if scrollback_idx < self.scrollback.len() {
208+
self.scrollback.get(scrollback_idx)
209+
} else {
210+
// Need to subtract scrollback offset
211+
// e.g. if we are showing 1 row of scrollback, and user requests 3rd visible row
212+
// we should return the second row in self.rows
213+
self.rows
214+
.get(usize::from(row).saturating_sub(self.scrollback_offset))
215+
}
202216
}
203217

204218
pub fn drawing_row(&self, row: u16) -> Option<&crate::row::Row> {

0 commit comments

Comments
 (0)