ui(feat): open expression suggestions with Ctrl+Space (#1852)

Thanks @Karl-VonRichter.
This commit is contained in:
Karl Von Richter authored and GitHub committed 2026-10-17 04:07:56 -04:00
1 parent ddc6aa6301
commit 3689f0d6e5
4 files changed
+80 -8

No files matched your search

+11 -3
View File
@@ -498,16 +498,24 @@ pub(crate) fn word_before(text: &str, cursor: usize) -> (usize, String) {
/// Suggestions for the word being typed.
pub fn suggestions(ctx: &egui::Context, word: &str) -> Vec<Suggestion> {
if word.is_empty() || word.chars().next().is_some_and(|c| c.is_ascii_digit()) {
suggestions_for(ctx, word, false)
}
pub(crate) fn suggestions_for(ctx: &egui::Context, word: &str, explicit: bool) -> Vec<Suggestion> {
if (!explicit && word.is_empty()) || word.chars().next().is_some_and(|c| c.is_ascii_digit()) {
return Vec::new();
}
let all = ctx.data(|d| d.get_temp::<Cache>(cache_id())).map(|c| c.all).unwrap_or_default();
// A complete token is ready to submit, even when longer names share its prefix.
if all.iter().any(|s| s.text == word) {
if !explicit && all.iter().any(|s| s.text == word) {
return Vec::new();
}
let w = word.to_ascii_lowercase();
all.iter().filter(|s| s.text.to_ascii_lowercase().starts_with(&w) && s.text.trim_end_matches('(') != word).take(8).cloned().collect()
all.iter()
.filter(|s| s.text.to_ascii_lowercase().starts_with(&w) && (explicit || s.text.trim_end_matches('(') != word))
.take(8)
.cloned()
.collect()
}
/// Offer keyboard and pointer completions under a focused expression box.