use super::component::Messages;
use tuirealm::MockComponent;
use tuirealm::command::{Cmd, Direction};
impl Messages {
pub fn move_down(&mut self) {
let current = self.current_index();
let max_index = self.message_count().saturating_sub(1);
if current < max_index {
self.component_mut().perform(Cmd::Move(Direction::Down));
}
}
pub fn move_up(&mut self) {
let current = self.current_index();
if current > 0 {
self.component_mut().perform(Cmd::Move(Direction::Up));
}
}
pub fn page_down(&mut self) {
let current = self.current_index();
let max_index = self.message_count().saturating_sub(1);
if current < max_index {
self.component_mut().perform(Cmd::Scroll(Direction::Down));
let new_index = self.current_index();
if new_index > max_index {
let moves_back = new_index - max_index;
for _ in 0..moves_back {
self.component_mut().perform(Cmd::Move(Direction::Up));
}
}
}
}
pub fn page_up(&mut self) {
self.component_mut().perform(Cmd::Scroll(Direction::Up));
}
}