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); + + } }