fix(resurrection): some ui fixes (#3264)
This commit is contained in:
parent
ee9aae789c
commit
5441309c5c
2 changed files with 41 additions and 21 deletions
|
|
@ -21,6 +21,9 @@ impl ResurrectableSessions {
|
|||
pub fn update(&mut self, mut list: Vec<(String, Duration)>) {
|
||||
list.sort_by(|a, b| a.1.cmp(&b.1));
|
||||
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) {
|
||||
if self.delete_all_dead_sessions_warning {
|
||||
|
|
@ -256,23 +259,29 @@ impl ResurrectableSessions {
|
|||
}
|
||||
}
|
||||
pub fn delete_selected_session(&mut self) {
|
||||
self.selected_index
|
||||
.and_then(|i| {
|
||||
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));
|
||||
if self.is_searching {
|
||||
self.selected_search_index
|
||||
.and_then(|i| self.search_results.get(i))
|
||||
.map(|search_result| delete_dead_session(&search_result.session_name));
|
||||
} else {
|
||||
self.selected_index
|
||||
.and_then(|i| {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|session_name_and_creation_time| {
|
||||
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) {
|
||||
// optimistic update
|
||||
|
|
@ -319,7 +328,18 @@ impl ResurrectableSessions {
|
|||
matches.sort_by(|a, b| b.score.cmp(&a.score));
|
||||
self.search_results = matches;
|
||||
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);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -436,10 +436,10 @@ fn find_resurrectable_sessions(
|
|||
{
|
||||
Ok(created) => Some(created),
|
||||
Err(e) => {
|
||||
if e.kind() != std::io::ErrorKind::NotFound {
|
||||
// let's not spam the
|
||||
// logs if serialization
|
||||
// is disabled
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
return None; // no layout file, cannot resurrect session, let's not
|
||||
// list it
|
||||
} else {
|
||||
log::error!(
|
||||
"Failed to read created stamp of resurrection file: {:?}",
|
||||
e
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue