mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Figure body snippets
This commit is contained in:
parent
65bb1fbe6a
commit
366348b196
@ -768,10 +768,16 @@ fn param_completions<'a>(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let apply = if param.name == "caption" {
|
||||||
|
eco_format!("{}: [${{}}]", param.name)
|
||||||
|
} else {
|
||||||
|
eco_format!("{}: ${{}}", param.name)
|
||||||
|
};
|
||||||
|
|
||||||
ctx.completions.push(Completion {
|
ctx.completions.push(Completion {
|
||||||
kind: CompletionKind::Param,
|
kind: CompletionKind::Param,
|
||||||
label: param.name.into(),
|
label: param.name.into(),
|
||||||
apply: Some(eco_format!("{}: ${{}}", param.name)),
|
apply: Some(apply),
|
||||||
detail: Some(plain_docs_sentence(param.docs)),
|
detail: Some(plain_docs_sentence(param.docs)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -807,8 +813,6 @@ fn param_value_completions<'a>(
|
|||||||
func: &Func,
|
func: &Func,
|
||||||
param: &'a ParamInfo,
|
param: &'a ParamInfo,
|
||||||
) {
|
) {
|
||||||
ctx.cast_completions(¶m.input);
|
|
||||||
|
|
||||||
if param.name == "font" {
|
if param.name == "font" {
|
||||||
ctx.font_completions();
|
ctx.font_completions();
|
||||||
} else if param.name == "path" {
|
} else if param.name == "path" {
|
||||||
@ -824,7 +828,12 @@ fn param_value_completions<'a>(
|
|||||||
Some("bibliography") => &["bib", "yml", "yaml"],
|
Some("bibliography") => &["bib", "yml", "yaml"],
|
||||||
_ => &[],
|
_ => &[],
|
||||||
});
|
});
|
||||||
|
} else if func.name() == Some("figure") && param.name == "body" {
|
||||||
|
ctx.snippet_completion("image", "image(\"${}\"),", "An image in a figure.");
|
||||||
|
ctx.snippet_completion("table", "table(\n ${}\n),", "A table in a figure.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.cast_completions(¶m.input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve a callee expression to a global function.
|
/// Resolve a callee expression to a global function.
|
||||||
@ -1704,4 +1713,13 @@ mod tests {
|
|||||||
test_with_path(&world, "content/b.typ", -2)
|
test_with_path(&world, "content/b.typ", -2)
|
||||||
.must_include([q!("../data/example.csv")]);
|
.must_include([q!("../data/example.csv")]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_autocomplete_figure_snippets() {
|
||||||
|
test("#figure()", -1)
|
||||||
|
.must_apply("image", "image(\"${}\"),")
|
||||||
|
.must_apply("table", "table(\n ${}\n),");
|
||||||
|
|
||||||
|
test("#figure(cap)", -1).must_apply("caption", "caption: [${}]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user