Skip to content

Commit

Permalink
Fix markdown completions with wikilinks on the same line
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 committed Mar 8, 2024
1 parent edc8a79 commit 243080f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@ use crate::{
};

fn get_wikilink_index(line: &Vec<char>, cursor_character: usize) -> Option<usize> {
line.get(0..=cursor_character)? // select only the characters up to the cursor
let index = line.get(0..=cursor_character)? // select only the characters up to the cursor
.iter()
.enumerate() // attach indexes
.tuple_windows() // window into pairs of characters
.collect::<Vec<(_, _)>>()
.into_iter()
.rev() // search from the cursor back
.find(|((_, &c1), (_, &c2))| c1 == '[' && c2 == '[')
.map(|(_, (i, _))| i) // only take the index; using map because find returns an option
.map(|(_, (i, _))| i); // only take the index; using map because find returns an option

index.and_then(|index| {
if line.get(index..cursor_character)?.into_iter().contains(&']') {
return None
} else {
return Some(index)
}
})
}

/// Range indexes for one line of the file; NOT THE WHOLE FILE
Expand Down

0 comments on commit 243080f

Please sign in to comment.