Skip to content

Commit

Permalink
fix: crash when selected item was changed and did not match the activ…
Browse files Browse the repository at this point in the history
…e filter anymore
  • Loading branch information
louis-thevenet committed Nov 30, 2024
1 parent af943f6 commit cb9acfa
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/components/explorer_tab.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color_eyre::owo_colors::OwoColorize;
use color_eyre::Result;
use crossterm::event::Event;
use layout::Flex;
Expand Down Expand Up @@ -83,18 +84,40 @@ impl<'a> ExplorerTab<'a> {
}
self.entries_center_view = match self.task_mgr.get_path_layer_entries(&self.current_path) {
Ok(res) => Self::vault_data_to_entry_list(&res),
Err(e) => {
self.leave_selected_entry()?;
vec![(String::from(WARNING_EMOJI), e.to_string())]
Err(_e) => {
// If no entries are found, go to parent object
while self
.task_mgr
.get_path_layer_entries(&self.current_path)
.is_err()
&& !self.current_path.is_empty()
{
self.leave_selected_entry()?;
}
Self::vault_data_to_entry_list(
&self
.task_mgr
.get_path_layer_entries(&self.current_path)
.unwrap_or_default(),
)
}
};
if self.state_left_view.selected.unwrap_or_default() >= self.entries_left_view.len() {
self.state_left_view.select(None);
} else {
self.select_previous_left_entry();
}
if self.state_center_view.selected.unwrap_or_default() >= self.entries_center_view.len() {
self.state_center_view.select(Some(0));
}
self.update_preview();
Ok(())
}

pub(super) fn update_preview(&mut self) {
debug!("Updating preview");
let Ok(path_to_preview) = self.get_preview_path() else {
self.entries_right_view = vec![];
return;
};

Expand Down Expand Up @@ -400,19 +423,6 @@ impl<'a> Component for ExplorerTab<'a> {
&self.config.tasks_config,
));
self.update_entries()?;
if self.state_left_view.selected.unwrap_or_default()
>= self.entries_left_view.len()
{
self.state_left_view.select(None);
} else {
self.select_previous_left_entry();
}
if self.state_center_view.selected.unwrap_or_default()
>= self.entries_center_view.len()
{
self.state_center_view.select(Some(0));
}
self.update_preview();
}
_ => (),
}
Expand Down

0 comments on commit cb9acfa

Please sign in to comment.