listing: add clear-selection command
Run cargo lints / Lint on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (pull_request) Successful in 9m36s Details
Run Tests / Test on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (pull_request) Successful in 15m27s Details

Add a command that performs what Escape does: clears the selection.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/341/head
Manos Pitsidianakis 2024-01-06 15:35:56 +02:00
parent 61a0c3c27f
commit cd448924ed
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
5 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -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)],

View File

@ -59,6 +59,7 @@ pub enum ListingAction {
OpenInNewTab,
Tag(TagAction),
Flag(FlagAction),
ClearSelection,
ToggleThreadSnooze,
}

View File

@ -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);

View File

@ -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)