Skip to content

Commit

Permalink
fix: handle vertical layout switch
Browse files Browse the repository at this point in the history
Synchronize line offsets when switching layout mode.
  • Loading branch information
luckasRanarison committed Aug 8, 2024
1 parent 7a151f3 commit e957c0c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/actors/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ impl Panel {
colors,
}
}

pub fn sync_lines(&mut self, width: u16) {
self.line_offsets = self
.logs
.iter()
.enumerate()
.flat_map(|(i, l)| vec![i; wrapped_lines(&l.0, width)])
.collect();
}
}

pub struct ConsoleActor {
Expand Down Expand Up @@ -326,8 +335,18 @@ impl ConsoleActor {
}
}

pub fn resize_panels(&mut self, width: u16) {
for panel in self.panels.values_mut() {
panel.shift = 0;
panel.sync_lines(width)
}
}

pub fn switch_layout(&mut self) {
self.layout_direction = self.layout_direction.get_opposite_orientation();
let f = self.terminal.get_frame();
let chunks = chunks(&self.mode, &self.layout_direction, &f);
self.resize_panels(chunks[0].width);
}
pub fn switch_mode(&mut self) {
self.mode = self.mode.get_opposite_mode();
Expand Down Expand Up @@ -455,18 +474,7 @@ impl Handler<TermEvent> for ConsoleActor {
},
_ => {}
},
Event::Resize(width, _) => {
for panel in self.panels.values_mut() {
panel.shift = 0;
let new_offsets = panel
.logs
.iter()
.enumerate()
.flat_map(|(i, l)| vec![i; wrapped_lines(&l.0, width)])
.collect();
panel.line_offsets = new_offsets;
}
}
Event::Resize(width, _) => self.resize_panels(width),
Event::Mouse(e) => match e.kind {
MouseEventKind::ScrollUp => {
self.up(1);
Expand Down

0 comments on commit e957c0c

Please sign in to comment.