Skip to content

Commit

Permalink
make "\alpha[tab]\alpha[tab]" competion possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Markos-Th09 committed Oct 31, 2023
1 parent 909f975 commit 80a9ba2
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,36 +499,34 @@ static GREEK_UPPERCASE_LETTERS: [(&str, &str); 24] = [

#[must_use]
pub fn get_completions_for_prefix(mut prefix: &str) -> (usize, Vec<Completion>) {
if let Some((prefix, letter)) = prefix.rsplit_once('\\') {
if letter.starts_with(|c: char| c.is_ascii_alphabetic()) && letter.len() <= 7 {
return if letter.starts_with(|c: char| c.is_ascii_uppercase()) {
GREEK_UPPERCASE_LETTERS
} else {
GREEK_LOWERCASE_LETTERS
}
.iter()
.find(|l| l.0 == letter)
.map_or((0, vec![]), |l| {
(
prefix.len(),
vec![Completion {
display: prefix.to_string(),
insert: l.1.to_string(),
}],
)
});
}
}

let mut prepend = "";
let position = prefix.len();
if let Some((a, b)) = prefix.rsplit_once(' ') {
prepend = a;
prefix = b;
}

if let Some(letter) = prefix.strip_prefix('\\') {
let position = prepend.len() + prepend.len().min(1);
if letter.starts_with(|c: char| !c.is_ascii_alphabetic()) {
return (0, vec![]);
}

return if letter.starts_with(|c: char| c.is_ascii_uppercase()) {
GREEK_UPPERCASE_LETTERS
} else {
GREEK_LOWERCASE_LETTERS
}
.iter()
.find(|l| l.0 == letter)
.map_or((0, vec![]), |l| {
(
position,
vec![Completion {
display: prefix.to_string(),
insert: l.1.to_string(),
}],
)
});
}
if prefix.is_empty() {
return (0, vec![]);
}
Expand Down

0 comments on commit 80a9ba2

Please sign in to comment.