From aab6b02db2925550ba0c7251dc6f1e48d5305cb6 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 10 Feb 2020 00:10:19 +0200 Subject: [PATCH] ui: clear selection with Esc --- src/components/mail/listing/compact.rs | 13 ++++++++++--- src/components/mail/listing/conversations.rs | 15 +++++++++++++++ src/components/mail/listing/plain.rs | 10 ++++++++++ src/components/mail/listing/thread.rs | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index 67a2da08..66d5b0c6 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -522,9 +522,6 @@ impl ListingTrait for CompactListing { self.filtered_order.clear(); self.filter_term = filter_term.to_string(); self.row_updates.clear(); - for v in self.selection.values_mut() { - *v = false; - } let account = &context.accounts[self.cursor_pos.0]; match account.search(&self.filter_term, self.sort, self.cursor_pos.1) { @@ -1343,6 +1340,16 @@ impl Component for CompactListing { UIEvent::Resize => { self.dirty = true; } + UIEvent::Input(Key::Esc) + if !self.unfocused + && self.selection.values().cloned().any(std::convert::identity) => + { + for v in self.selection.values_mut() { + *v = false; + } + self.dirty = true; + return true; + } UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => { self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1)); self.refresh_mailbox(context, false); diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index d6b7cda6..c7758e8c 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -100,6 +100,7 @@ impl MailListingTrait for ConversationsListing { from: crate::conf::value(context, "mail.listing.conversations.from"), date: crate::conf::value(context, "mail.listing.conversations.date"), padding: crate::conf::value(context, "mail.listing.conversations.padding"), + selected: crate::conf::value(context, "mail.listing.compact.selected"), unseen: crate::conf::value(context, "mail.listing.conversations.unseen"), unseen_padding: crate::conf::value( context, @@ -196,6 +197,10 @@ impl ListingTrait for ConversationsListing { let fg_color = if thread.unseen() > 0 { self.color_cache.unseen.fg + } else if self.cursor_pos.2 == idx { + self.color_cache.highlighted.fg + } else if self.selection[&thread_hash] { + self.color_cache.selected.fg } else { self.color_cache.theme_default.fg }; @@ -1294,6 +1299,16 @@ impl Component for ConversationsListing { } _ => {} }, + UIEvent::Input(Key::Esc) + if !self.unfocused + && self.selection.values().cloned().any(std::convert::identity) => + { + for v in self.selection.values_mut() { + *v = false; + } + self.dirty = true; + return true; + } UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Char('')) if !self.unfocused && !&self.filter_term.is_empty() => { diff --git a/src/components/mail/listing/plain.rs b/src/components/mail/listing/plain.rs index 1156d8e4..203a8a8d 100644 --- a/src/components/mail/listing/plain.rs +++ b/src/components/mail/listing/plain.rs @@ -1171,6 +1171,16 @@ impl Component for PlainListing { UIEvent::Resize => { self.dirty = true; } + UIEvent::Input(Key::Esc) + if !self.unfocused + && self.selection.values().cloned().any(std::convert::identity) => + { + for v in self.selection.values_mut() { + *v = false; + } + self.dirty = true; + return true; + } UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => { self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1)); self.set_dirty(true); diff --git a/src/components/mail/listing/thread.rs b/src/components/mail/listing/thread.rs index 6cad1054..c6bf3216 100644 --- a/src/components/mail/listing/thread.rs +++ b/src/components/mail/listing/thread.rs @@ -527,6 +527,7 @@ impl Component for ThreadListing { if self.length == 0 && self.dirty { clear_area(grid, area, self.color_cache.theme_default); context.dirty_areas.push_back(area); + return; } /* Render the mail body in a pager, basically copy what HSplit does */