diff --git a/meli/docs/meli.7 b/meli/docs/meli.7 index c2bd962a..f1de19ec 100644 --- a/meli/docs/meli.7 +++ b/meli/docs/meli.7 @@ -467,6 +467,9 @@ you can use the following commands on entries and selections to modify them: and .Ic ignore_tags for how to set tag colors and tag visibility) +You can clear the selection with the +.Aq Esc +key. .Sh PAGER You can open an e-mail entry by pressing .ShortcutPeriod Enter listing open_entry diff --git a/meli/src/mail/listing.rs b/meli/src/mail/listing.rs index 0c67bf59..105d5661 100644 --- a/meli/src/mail/listing.rs +++ b/meli/src/mail/listing.rs @@ -1661,14 +1661,21 @@ impl Component for Listing { | Action::Listing(a @ ListingAction::Tag(_)) => { let focused = self.component.get_focused_items(context); self.component.perform_action(context, focused, a); + let should_be_unselected: bool = matches!( + a, + ListingAction::Delete + | ListingAction::MoveTo(_) + | ListingAction::MoveToOtherAccount(_, _) + ); let mut row_updates: SmallVec<[EnvelopeHash; 8]> = SmallVec::new(); for (k, v) in self.component.selection().iter_mut() { if *v { - *v = false; + *v = !should_be_unselected; row_updates.push(*k); } } self.component.row_updates().extend(row_updates); + return true; } _ => {} }, @@ -1867,6 +1874,7 @@ impl Component for Listing { && self.component.modifier_command().is_some() => { self.component.set_modifier_command(Some(Modifier::Union)); + return true; } UIEvent::Input(ref key) if !self.component.unfocused() @@ -1875,6 +1883,7 @@ impl Component for Listing { { self.component .set_modifier_command(Some(Modifier::Difference)); + return true; } UIEvent::Input(ref key) if !self.component.unfocused() @@ -1885,12 +1894,14 @@ impl Component for Listing { { self.component .set_modifier_command(Some(Modifier::Intersection)); + return true; } UIEvent::Input(ref key) if self.component.unfocused() && shortcut!(key == shortcuts[Shortcuts::LISTING]["next_entry"]) => { self.component.next_entry(context); + return true; } UIEvent::Input(ref key) if self.component.unfocused() @@ -1899,9 +1910,26 @@ impl Component for Listing { ) => { self.component.prev_entry(context); + return true; } - _ => {} + UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt('')) + if !self.component.unfocused() => + { + // Clear selection. + let row_updates: SmallVec<[EnvelopeHash; 8]> = + self.component.get_focused_items(context); + for h in &row_updates { + if let Some(val) = self.component.selection().get_mut(h) { + *val = false; + } + } + self.component.row_updates().extend(row_updates); + self.component.set_dirty(true); + return true; + } + _ => return false, } + return true; } } else if self.focus == ListingFocus::Menu { match *event { diff --git a/meli/src/mail/listing/compact.rs b/meli/src/mail/listing/compact.rs index 886e87e0..3f84e0ab 100644 --- a/meli/src/mail/listing/compact.rs +++ b/meli/src/mail/listing/compact.rs @@ -2019,21 +2019,6 @@ impl Component for CompactListing { UIEvent::Resize => { self.set_dirty(true); } - UIEvent::Input(Key::Esc) - if !self.unfocused() - && self - .rows - .selection - .values() - .cloned() - .any(std::convert::identity) => - { - for v in self.rows.selection.values_mut() { - *v = false; - } - self.set_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/meli/src/mail/listing/conversations.rs b/meli/src/mail/listing/conversations.rs index 1da2ffba..c657c408 100644 --- a/meli/src/mail/listing/conversations.rs +++ b/meli/src/mail/listing/conversations.rs @@ -1468,19 +1468,6 @@ impl Component for ConversationsListing { } _ => {} }, - UIEvent::Input(Key::Esc) - if !self.unfocused() - && self - .rows - .selection - .values() - .cloned() - .any(std::convert::identity) => - { - self.rows.clear_selection(); - self.set_dirty(true); - return true; - } UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Char('')) if !self.unfocused() && !&self.filter_term.is_empty() => { diff --git a/meli/src/mail/listing/plain.rs b/meli/src/mail/listing/plain.rs index 4bd3e0f8..fbc43825 100644 --- a/meli/src/mail/listing/plain.rs +++ b/meli/src/mail/listing/plain.rs @@ -1718,19 +1718,6 @@ impl Component for PlainListing { UIEvent::Resize => { self.set_dirty(true); } - UIEvent::Input(Key::Esc) - if !self.unfocused() - && self - .rows - .selection - .values() - .cloned() - .any(std::convert::identity) => - { - self.rows.clear_selection(); - self.set_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/meli/src/mail/listing/thread.rs b/meli/src/mail/listing/thread.rs index a0b026f4..18475bd7 100644 --- a/meli/src/mail/listing/thread.rs +++ b/meli/src/mail/listing/thread.rs @@ -1585,21 +1585,6 @@ impl Component for ThreadListing { UIEvent::Resize => { self.set_dirty(true); } - UIEvent::Input(Key::Esc) - if !self.unfocused() - && self - .rows - .selection - .values() - .cloned() - .any(std::convert::identity) => - { - for v in self.rows.selection.values_mut() { - *v = false; - } - self.set_dirty(true); - return true; - } UIEvent::Input(ref key) if !self.unfocused() && shortcut!(key == shortcuts[Shortcuts::LISTING]["select_entry"]) =>