Make docs align with actual behavior

This commit is contained in:
T0mstone 2025-07-23 14:22:16 +02:00
parent 70f619e896
commit 6594a0f530

View File

@ -720,24 +720,26 @@ fn symbols_model(resolver: &dyn Resolver, group: &GroupData) -> SymbolsModel {
for (variant, value, deprecation) in symbol.variants() { for (variant, value, deprecation) in symbol.variants() {
let value_char = value.parse::<char>().ok(); let value_char = value.parse::<char>().ok();
let shorthand = |list: &[(&'static str, char)]| { let shorthand = |list: &[(&'static str, char)]| {
value_char.and_then(|c| { value_char.and_then(|c| {
list.iter().copied().find(|&(_, x)| x == c).map(|(s, _)| s) list.iter().copied().find(|&(_, x)| x == c).map(|(s, _)| s)
}) })
}; };
let base_char = base_char(value);
let name = complete(variant); let name = complete(variant);
list.push(SymbolModel { list.push(SymbolModel {
name, name,
markup_shorthand: shorthand(typst::syntax::ast::Shorthand::LIST), markup_shorthand: shorthand(typst::syntax::ast::Shorthand::LIST),
math_shorthand: shorthand(typst::syntax::ast::MathShorthand::LIST), math_shorthand: shorthand(typst::syntax::ast::MathShorthand::LIST),
math_class: base_char.and_then(|c| { // Matches `typst_layout::math::GlyphFragment::new`
math_class: value.chars().next().and_then(|c| {
typst_utils::default_math_class(c).map(math_class_name) typst_utils::default_math_class(c).map(math_class_name)
}), }),
value: value.into(), value: value.into(),
accent: base_char // Matches casting `Symbol` to `Accent`
accent: value_char
.is_some_and(|c| typst::math::Accent::combine(c).is_some()), .is_some_and(|c| typst::math::Accent::combine(c).is_some()),
alternates: symbol alternates: symbol
.variants() .variants()
@ -778,13 +780,6 @@ pub fn urlify(title: &str) -> EcoString {
.collect() .collect()
} }
/// Convert a string to a `char`, ignoring any suffixed variation selectors.
fn base_char(value: &str) -> Option<char> {
value.trim_end_matches(|c: char| {
matches!(c, '\u{180B}'..='\u{180D}' | '\u{180F}' | '\u{FE00}'..='\u{FE0F}' | '\u{E0100}'..='\u{E01EF}')
}).parse::<char>().ok()
}
/// Extract the first line of documentation. /// Extract the first line of documentation.
fn oneliner(docs: &str) -> EcoString { fn oneliner(docs: &str) -> EcoString {
let paragraph = docs.split("\n\n").next().unwrap_or_default(); let paragraph = docs.split("\n\n").next().unwrap_or_default();