fix(resurrection): some ui fixes (#3264)

This commit is contained in:
Aram Drevekenin 2024-04-15 17:06:29 +02:00 committed by GitHub
parent ee9aae789c
commit 5441309c5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 21 deletions

View file

@ -21,6 +21,9 @@ impl ResurrectableSessions {
pub fn update(&mut self, mut list: Vec<(String, Duration)>) { pub fn update(&mut self, mut list: Vec<(String, Duration)>) {
list.sort_by(|a, b| a.1.cmp(&b.1)); list.sort_by(|a, b| a.1.cmp(&b.1));
self.all_resurrectable_sessions = list; self.all_resurrectable_sessions = list;
if self.is_searching {
self.update_search_term();
}
} }
pub fn render(&self, rows: usize, columns: usize, x: usize, y: usize) { pub fn render(&self, rows: usize, columns: usize, x: usize, y: usize) {
if self.delete_all_dead_sessions_warning { if self.delete_all_dead_sessions_warning {
@ -256,23 +259,29 @@ impl ResurrectableSessions {
} }
} }
pub fn delete_selected_session(&mut self) { pub fn delete_selected_session(&mut self) {
self.selected_index if self.is_searching {
.and_then(|i| { self.selected_search_index
if self.all_resurrectable_sessions.len() > i { .and_then(|i| self.search_results.get(i))
// optimistic update .map(|search_result| delete_dead_session(&search_result.session_name));
if i == 0 { } else {
self.selected_index = None; self.selected_index
} else if i == self.all_resurrectable_sessions.len().saturating_sub(1) { .and_then(|i| {
self.selected_index = Some(i.saturating_sub(1)); if self.all_resurrectable_sessions.len() > i {
// optimistic update
if i == 0 {
self.selected_index = None;
} else if i == self.all_resurrectable_sessions.len().saturating_sub(1) {
self.selected_index = Some(i.saturating_sub(1));
}
Some(self.all_resurrectable_sessions.remove(i))
} else {
None
} }
Some(self.all_resurrectable_sessions.remove(i)) })
} else { .map(|session_name_and_creation_time| {
None delete_dead_session(&session_name_and_creation_time.0)
} });
}) }
.map(|session_name_and_creation_time| {
delete_dead_session(&session_name_and_creation_time.0)
});
} }
fn delete_all_sessions(&mut self) { fn delete_all_sessions(&mut self) {
// optimistic update // optimistic update
@ -319,7 +328,18 @@ impl ResurrectableSessions {
matches.sort_by(|a, b| b.score.cmp(&a.score)); matches.sort_by(|a, b| b.score.cmp(&a.score));
self.search_results = matches; self.search_results = matches;
self.is_searching = !self.search_term.is_empty(); self.is_searching = !self.search_term.is_empty();
self.selected_search_index = Some(0); match self.selected_search_index {
Some(search_index) => {
if self.search_results.is_empty() {
self.selected_search_index = None;
} else if search_index >= self.search_results.len() {
self.selected_search_index = Some(self.search_results.len().saturating_sub(1));
}
},
None => {
self.selected_search_index = Some(0);
},
}
} }
} }

View file

@ -436,10 +436,10 @@ fn find_resurrectable_sessions(
{ {
Ok(created) => Some(created), Ok(created) => Some(created),
Err(e) => { Err(e) => {
if e.kind() != std::io::ErrorKind::NotFound { if e.kind() == std::io::ErrorKind::NotFound {
// let's not spam the return None; // no layout file, cannot resurrect session, let's not
// logs if serialization // list it
// is disabled } else {
log::error!( log::error!(
"Failed to read created stamp of resurrection file: {:?}", "Failed to read created stamp of resurrection file: {:?}",
e e