M4: a link on text is underlined by default, and Underline takes it off (#1841)

* M4: a link on text is underlined by default, and Underline takes it off

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* text.link: only a new link takes the default underline; Underline reads the texts inside a target

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Trevor Brown
2026-11-01 23:49:48 -05:00
committed by GitHub
co-authored by Claude Fable 5.1
parent fdd27a0b88
commit 3b8ded69c0
3 changed files with 57 additions and 6 deletions
+21 -5
View File
@@ -101,7 +101,9 @@ fn all_have(s: &Session, p: &Value, pred: impl Fn(&TextStyle) -> bool) -> bool {
}
return false;
}
targets(s, p).iter().all(|i| matches!(doc.node(*i).map(|n| &n.kind), Some(NodeKind::Text(t)) if t.spans().iter().all(|(_, _, st)| pred(st))))
// The texts `style` restyles: the targets and the texts inside them.
let texts: Vec<&TextData> = targets(s, p).iter().flat_map(|i| doc.subtree(*i)).filter_map(|d| doc.node(d).and_then(|n| n.kind.text())).collect();
!texts.is_empty() && texts.iter().all(|t| t.spans().iter().all(|(_, _, st)| pred(st)))
}
fn toggle_bold(s: &mut Session, p: &Value) -> Result<Value> {
@@ -217,10 +219,24 @@ pub fn specs() -> Vec<CommandSpec> {
let on = all_have(s, p, |st| st.decoration == TextDecoration::Strikethrough);
style(s, p, |st| st.decoration = if on { TextDecoration::None } else { TextDecoration::Strikethrough })
}),
spec!("text.link", "Create link", "{url, ids?}", true, |s, p| {
let url = req_string("text.link", p, "url")?;
style(s, p, |st| st.link = Some(url.clone()))
}),
spec!(
"text.link",
"Create link",
"{url, ids?} linked text is underlined unless it has a decoration of its own (Underline takes it off again)",
true,
|s, p| {
let url = req_string("text.link", p, "url")?;
style(s, p, |st| {
// "Links are styled with an underline by default" (Add links to text); Underline
// (Cmd/Ctrl+U) removes it, as documented there, and changing the URL of a link
// leaves its decoration as it is.
if st.link.is_none() && st.decoration == TextDecoration::None {
st.decoration = TextDecoration::Underline;
}
st.link = Some(url.clone());
})
}
),
spec!("text.bulletList", "Bulleted list", "{ids?} while editing: the selected paragraphs", true, |s, p| set_list(
s,
p,