From 6c7e46a0e41fba11d2672b9a6e830b187bef2211 Mon Sep 17 00:00:00 2001 From: Felix Zeller Date: Tue, 12 Mar 2024 22:51:24 -0400 Subject: [PATCH] fix: tags on one line closes to #31 --- src/completion.rs | 55 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/completion.rs b/src/completion.rs index bad00745..ebbbcebd 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -120,24 +120,30 @@ fn get_completable_tag(line: &Vec, cursor_character: usize) -> Option= full.range().start && preceding_character < full.range().end { // end is exclusive + return Some(CompletableTag { + full_range: full.range(), + inputted_tag: (tag_text.as_str().to_string(), tag_text.range()) + }) + } else { + return None + } - // check if the cursor is in the tag - let preceding_character = cursor_character - 1; // User is inserting into the position after the character they are looking at; "#tag|" cursor is a position 4; I want pos 3; the end of the tag - if preceding_character >= full.range().start && preceding_character < full.range().end { // end is exclusive - return Some(CompletableTag { - full_range: full.range(), - inputted_tag: (tag_text.as_str().to_string(), tag_text.range()) }) - } else { - return None - } + .next() + } @@ -819,6 +825,23 @@ mod tests { assert_eq!(expected, actual); + // 0 1 2 + // 01234567890123456789012345678 + let text = "text over here #tag mor #tag "; + + let insert_position = 28; + + let expected = CompletableTag { + full_range: 24..28, + inputted_tag: ("tag".to_string(), 25..28) // not inclusive + }; + + let actual = get_completable_tag(&text.chars().collect_vec(), insert_position); + + + assert_eq!(Some(expected), actual); + + } }