From 1bb024ca3f75cf9cbad1ef3ff321d3c298dce609 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 6 Jul 2023 16:09:37 +0200 Subject: [PATCH] Fix autocompletion for dictionary key with spaces --- crates/typst/src/ide/complete.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/typst/src/ide/complete.rs b/crates/typst/src/ide/complete.rs index 16cba1bc6..2c9c386e2 100644 --- a/crates/typst/src/ide/complete.rs +++ b/crates/typst/src/ide/complete.rs @@ -1042,14 +1042,8 @@ impl<'a> CompletionContext<'a> { parens: bool, docs: Option<&str>, ) { + let at = label.as_deref().map_or(false, |field| !is_ident(field)); let label = label.unwrap_or_else(|| value.repr().into()); - let mut apply = None; - - if label.starts_with('"') && self.after.starts_with('"') { - if let Some(trimmed) = label.strip_suffix('"') { - apply = Some(trimmed.into()); - } - } let detail = docs.map(Into::into).or_else(|| match value { Value::Symbol(_) => None, @@ -1060,8 +1054,15 @@ impl<'a> CompletionContext<'a> { } }); + let mut apply = None; if parens && matches!(value, Value::Func(_)) { apply = Some(eco_format!("{label}(${{}})")); + } else if at { + apply = Some(eco_format!("at(\"{label}\")")); + } else if label.starts_with('"') && self.after.starts_with('"') { + if let Some(trimmed) = label.strip_suffix('"') { + apply = Some(trimmed.into()); + } } self.completions.push(Completion {