From 909f975c771b153f31ae19e508560d56f954f9dd Mon Sep 17 00:00:00 2001 From: MarkosTh09 Date: Tue, 31 Oct 2023 13:29:08 +0400 Subject: [PATCH 1/2] fix insertion --- core/src/lib.rs | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 7daa741e..58dd8c5b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -505,35 +505,29 @@ pub fn get_completions_for_prefix(mut prefix: &str) -> (usize, Vec) 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![]); - } else if letter.starts_with(|c: char| c.is_ascii_uppercase()) { - return GREEK_UPPERCASE_LETTERS - .iter() - .find(|l| l.0 == letter) - .map_or((0, vec![]), |l| { - ( - 0, - vec![Completion { - display: prefix.to_string(), - insert: l.1.to_string(), - }], - ) - }); } - return GREEK_LOWERCASE_LETTERS - .iter() - .find(|l| l.0 == letter) - .map_or((0, vec![]), |l| { - ( - 0, - vec![Completion { - display: prefix.to_string(), - insert: l.1.to_string(), - }], - ) - }); + + 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![]); From 80a9ba208dca7ba1f696e5c231f13bba02864e01 Mon Sep 17 00:00:00 2001 From: MarkosTh09 Date: Tue, 31 Oct 2023 16:14:03 +0400 Subject: [PATCH 2/2] make "\alpha[tab]\alpha[tab]" competion possible --- core/src/lib.rs | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 58dd8c5b..2ab916d8 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -499,6 +499,27 @@ static GREEK_UPPERCASE_LETTERS: [(&str, &str); 24] = [ #[must_use] pub fn get_completions_for_prefix(mut prefix: &str) -> (usize, Vec) { + 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(' ') { @@ -506,29 +527,6 @@ pub fn get_completions_for_prefix(mut prefix: &str) -> (usize, Vec) 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![]); }