forked from janek/mostr
1
0
Fork 0

fix(tasks): revamp tag delimiter in task creation syntax

Prevent accidental interpretation of title parts as tags
This commit is contained in:
xeruf 2024-11-08 12:15:32 +01:00
parent 5303d0cb41
commit dd78a2f460
3 changed files with 8 additions and 7 deletions

View File

@ -87,7 +87,7 @@ To stop time-tracking completely, simply move to the root of all tasks.
### Command Syntax
`TASK` creation syntax: `NAME: TAG1 TAG2 ...`
`TASK` creation syntax: `NAME #TAG *PRIO # TAG1 TAG2 ...`
- `TASK` - create task
+ prefix with space if you want a task to start with a command character

View File

@ -91,11 +91,12 @@ pub(crate) fn extract_hashtags(input: &str) -> impl Iterator<Item=Tag> + '_ {
.map(to_hashtag)
}
/// Extracts everything after a ": " as a list of tags.
/// Extracts everything after a " # " as a list of tags
/// as well as various embedded tags.
///
/// Expects sanitized input.
pub(crate) fn extract_tags(input: &str) -> (&str, Vec<Tag>) {
match input.split_once(": ") {
match input.split_once(" # ") {
None => (input, extract_hashtags(input).collect_vec()),
Some((name, tags)) => {
let tags = extract_hashtags(name)
@ -139,6 +140,6 @@ pub(crate) fn is_hashtag(tag: &Tag) -> bool {
#[test]
fn test_extract_tags() {
assert_eq!(extract_tags("Hello from #mars with #greetings: yeah done-it"),
assert_eq!(extract_tags("Hello from #mars with #greetings # yeah done-it"),
("Hello from #mars with #greetings", ["mars", "greetings", "yeah", "done-it"].into_iter().map(to_hashtag).collect()))
}

View File

@ -1582,7 +1582,7 @@ mod tasks_test {
fn test_bookmarks() {
let mut tasks = stub_tasks();
let zero = EventId::all_zeros();
let test = tasks.make_task("test: tag");
let test = tasks.make_task("test # tag");
let parent = tasks.make_task("parent");
assert_eq!(tasks.visible_tasks().len(), 2);
tasks.move_to(Some(parent));
@ -1622,7 +1622,7 @@ mod tasks_test {
#[test]
fn test_procedures() {
let mut tasks = stub_tasks();
tasks.make_task_and_enter("proc: tags", State::Procedure);
tasks.make_task_and_enter("proc # tags", State::Procedure);
assert_eq!(tasks.get_own_events_history().count(), 1);
let side = tasks.submit(
build_task("side", vec![tasks.make_event_tag(&tasks.get_current_task().unwrap().event, MARKER_DEPENDS)], None));
@ -1738,7 +1738,7 @@ mod tasks_test {
assert_position!(tasks, t1);
tasks.search_depth = 2;
assert_eq!(tasks.visible_tasks().len(), 0);
let t11 = tasks.make_task("t11: tag");
let t11 = tasks.make_task("t11 # tag");
assert_eq!(tasks.visible_tasks().len(), 1);
assert_eq!(tasks.get_task_path(Some(t11)), "t1>t11");
assert_eq!(tasks.relative_path(t11), "t11");