listing: add clear-selection command
Add a command that performs what Escape does: clears the selection. Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>pull/341/head
parent
61a0c3c27f
commit
cd448924ed
|
@ -452,6 +452,8 @@ Escape exits search results.
|
|||
select threads matching
|
||||
.Ar STRING
|
||||
query.
|
||||
.It Cm clear-selection
|
||||
Clear current selection.
|
||||
.It Cm set seen, set unseen
|
||||
Set seen status of message.
|
||||
.It Cm import Ar FILEPATH Ar MAILBOX_PATH
|
||||
|
|
|
@ -340,6 +340,11 @@ define_commands!([
|
|||
tokens: &[One(Literal("search")), One(RestOfStringValue)],
|
||||
parser: parser::search
|
||||
},
|
||||
{ tags: ["clear-selection"],
|
||||
desc: "clear-selection",
|
||||
tokens: &[One(Literal("clear-selection"))],
|
||||
parser: parser::select
|
||||
},
|
||||
{ tags: ["select"],
|
||||
desc: "select <TERM>, selects envelopes matching with given term",
|
||||
tokens: &[One(Literal("select")), One(RestOfStringValue)],
|
||||
|
|
|
@ -59,6 +59,7 @@ pub enum ListingAction {
|
|||
OpenInNewTab,
|
||||
Tag(TagAction),
|
||||
Flag(FlagAction),
|
||||
ClearSelection,
|
||||
ToggleThreadSnooze,
|
||||
}
|
||||
|
||||
|
|
|
@ -464,6 +464,26 @@ pub fn search(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
|
|||
Ok((input, Ok(Listing(Search(String::from(string))))))
|
||||
}
|
||||
pub fn select(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
|
||||
#[inline]
|
||||
fn clear_selection(input: &[u8]) -> Option<IResult<&[u8], Result<Action, CommandError>>> {
|
||||
if !input.trim().starts_with(b"clear-selection") {
|
||||
return None;
|
||||
}
|
||||
#[inline]
|
||||
fn inner(input: &[u8]) -> IResult<&[u8], Result<Action, CommandError>> {
|
||||
let mut check = arg_init! { min_arg:0, max_arg: 0, clear_selection};
|
||||
let (input, _) = tag("clear-selection")(input.ltrim())?;
|
||||
arg_chk!(start check, input);
|
||||
arg_chk!(finish check, input);
|
||||
let (input, _) = eof(input)?;
|
||||
Ok((input, Ok(Listing(ListingAction::ClearSelection))))
|
||||
}
|
||||
Some(inner(input))
|
||||
}
|
||||
if let Some(retval) = clear_selection(input) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
let mut check = arg_init! { min_arg:1, max_arg: {u8::MAX}, select};
|
||||
let (input, _) = tag("select")(input.trim())?;
|
||||
arg_chk!(start check, input);
|
||||
|
|
|
@ -1677,6 +1677,19 @@ impl Component for Listing {
|
|||
self.component.row_updates().extend(row_updates);
|
||||
return true;
|
||||
}
|
||||
Action::Listing(ListingAction::ClearSelection) => {
|
||||
// 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;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
UIEvent::Input(ref key)
|
||||
|
|
Loading…
Reference in New Issue