Skip to content

Commit 13e36cc

Browse files
author
tlipinski
committed
refactor: simplify scroll offset calculations and remove redundant resize logic
1 parent 6ab0749 commit 13e36cc

1 file changed

Lines changed: 3 additions & 19 deletions

File tree

src/output_widget.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,12 @@ impl OutputWidget {
179179
pub fn handle_ui_command(&mut self, ui_cmd: UiCmd) {
180180
match ui_cmd {
181181
UiCmd::ScrollDown => {
182-
let max_offset = self
183-
.main_output()
184-
.lines
185-
.len()
186-
.saturating_sub(self.output_height as usize);
182+
let max_offset = self.main_output().lines.len().saturating_sub(1); // keep at least one line visible
183+
187184
self.offset.y = self.offset.y.saturating_add(1).min(max_offset);
188185
}
189186
UiCmd::ScrollDownPage => {
190-
let max_offset = self
191-
.main_output()
192-
.lines
193-
.len()
194-
.saturating_sub(self.output_height as usize);
187+
let max_offset = self.main_output().lines.len().saturating_sub(1); // keep at least one line visible
195188

196189
let page_size = self.output_height as usize / 2;
197190
self.offset.y = self.offset.y.saturating_add(page_size).min(max_offset);
@@ -274,15 +267,6 @@ impl Widget for &mut OutputWidget {
274267

275268
self.output_height = output_content_area.height; // save this value for scroll logic
276269

277-
// it screen was resized (height increased) then adjust current offset
278-
let current_max_y_offset = self
279-
.main_output()
280-
.len()
281-
.saturating_sub(output_content_area.height as usize);
282-
if self.offset.y > current_max_y_offset {
283-
self.offset.y = current_max_y_offset
284-
}
285-
286270
if matches!(self.error_display_mode, ErrorDisplayMode::Pane) {
287271
if let Some(err_output) = &self.error_output_opt {
288272
let block = Block::bordered()

0 commit comments

Comments
 (0)