From 7f34a888f33f112b6235e1a293f6c64d954dae1d Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 1 Aug 2024 20:12:04 +0300 Subject: [PATCH] feat: make tags sticky and allow manual removal --- README.md | 3 ++- src/main.rs | 6 +++++- src/tasks.rs | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7849e78..26b7952 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,8 @@ Dots can be repeated to move to parent tasks. Property Filters: -- `#TAG` - filter by tag +- `+TAG` - filter by tag +- `-TAG` - remove filter by tag - `?STATE` - filter by state (type or description) - plain `?` to reset State descriptions can be used for example for Kanban columns or review flows. diff --git a/src/main.rs b/src/main.rs index b43e11f..a21def6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -337,9 +337,13 @@ async fn main() { } }, - Some('#') => { + Some('#') | Some('+') => { tasks.add_tag(arg.to_string()); } + + Some('-') => { + tasks.remove_tag(arg.to_string()) + } Some('.') => { let mut dots = 1; diff --git a/src/tasks.rs b/src/tasks.rs index 23ac2c0..bdb411a 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -364,6 +364,11 @@ impl Tasks { self.tags.insert(Hashtag(tag)); } + pub(crate) fn remove_tag(&mut self, tag: String) { + self.view.clear(); + self.tags.retain(|t| !t.content().is_some_and(|value| value.to_string().starts_with(&tag))); + } + pub(crate) fn set_state_filter(&mut self, state: Option) { self.view.clear(); self.state = state; @@ -379,7 +384,6 @@ impl Tasks { pub(crate) fn move_to(&mut self, id: Option) { self.view.clear(); - self.tags.clear(); // TODO unsure if this is needed, needs alternative way to clear if id == self.position { debug!("Flushing Tasks because of move in place"); self.flush(); @@ -393,7 +397,7 @@ impl Tasks { ) ); if !id.and_then(|id| self.tasks.get(&id)).is_some_and(|t| t.parent_id() == self.position.as_ref()) { - debug!("Flushing Tasks because of move upwards"); + debug!("Flushing Tasks because of move"); self.flush(); } self.position = id;