forked from janek/mostr
feat: implicit Task activation
Automatically mark the selected task as active
This commit is contained in:
parent
ab16b87497
commit
3968e5c1ae
1 changed files with 25 additions and 7 deletions
32
src/main.rs
32
src/main.rs
|
@ -167,15 +167,23 @@ async fn repl() {
|
||||||
|
|
||||||
Some('>') | Some('<') => {
|
Some('>') | Some('<') => {
|
||||||
position.inspect(|e| {
|
position.inspect(|e| {
|
||||||
let pos = tasks.get(e)
|
tasks.get_mut(e).map(|t| t.props.push(make_event(
|
||||||
.and_then(|t| t.state())
|
(if op.unwrap() == '<' { Closed } else { Done }).kind(), &input[1..], &[Tag::event(e.clone())])));
|
||||||
.and_then(|state| STATES.iter().position(|s| s == &state.state))
|
|
||||||
.unwrap_or(1);
|
|
||||||
tasks.get_mut(e).map(|t| t.props.push(make_event(STATES[if op.unwrap() == '<' { pos - 1 } else { pos + 1 }].kind(), &input[1..], &[Tag::event(e.clone())])));
|
|
||||||
});
|
});
|
||||||
|
position = position
|
||||||
|
.and_then(|id| tasks.get_mut(&id))
|
||||||
|
.and_then(|t| t.parent_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
Some('.') => {
|
Some('.') => {
|
||||||
|
if input.len() > 1 {
|
||||||
|
position.and_then(|p| tasks.get_mut(&p))
|
||||||
|
.map(|t| {
|
||||||
|
if t.state().map(|s| s.state) == Some(Active) {
|
||||||
|
t.update_state(Open, "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
let mut dots = 1;
|
let mut dots = 1;
|
||||||
for _ in iter.take_while(|c| c == &'.') {
|
for _ in iter.take_while(|c| c == &'.') {
|
||||||
dots += 1;
|
dots += 1;
|
||||||
|
@ -190,6 +198,12 @@ async fn repl() {
|
||||||
let ret = Some(task.id);
|
let ret = Some(task.id);
|
||||||
add_task(&mut tasks, task);
|
add_task(&mut tasks, task);
|
||||||
ret
|
ret
|
||||||
|
}).inspect(|id| {
|
||||||
|
tasks.get_mut(id).map(|t|
|
||||||
|
if t.state().map_or(Open, |s| s.state) == Open {
|
||||||
|
t.update_state(Active, "")
|
||||||
|
}
|
||||||
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,6 +319,10 @@ impl Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_state(&mut self, state: State, comment: &str) {
|
||||||
|
self.props.push(make_event(state.kind(), comment, &[Tag::event(self.event.id)]))
|
||||||
|
}
|
||||||
|
|
||||||
fn get(&self, property: &str) -> Option<String> {
|
fn get(&self, property: &str) -> Option<String> {
|
||||||
match property {
|
match property {
|
||||||
"id" => Some(self.event.id.to_string()),
|
"id" => Some(self.event.id.to_string()),
|
||||||
|
@ -346,10 +364,10 @@ enum State {
|
||||||
impl State {
|
impl State {
|
||||||
fn kind(&self) -> Kind {
|
fn kind(&self) -> Kind {
|
||||||
match self {
|
match self {
|
||||||
Closed => Kind::from(1632),
|
|
||||||
Open => Kind::from(1630),
|
Open => Kind::from(1630),
|
||||||
Active => Kind::from(1633),
|
|
||||||
Done => Kind::from(1631),
|
Done => Kind::from(1631),
|
||||||
|
Closed => Kind::from(1632),
|
||||||
|
Active => Kind::from(1633),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue