Compare commits

...
Author SHA1 Message Date
autocraft-bot[bot] ba887ee766 Merge main (4680b9a2) into the pull request
Resolved the only conflict, the "Last reviewed / Last updated / Change" 

Resolved the only conflict, the "Last reviewed / Last updated / Change" header line in `docs/typing-parity.md`. The single header now has this pull request's #8541 entry first, dated 2026-12-04, then main's #4287 entry (a list item that changes level) as "previously minor", then the earlier entries both sides shared. The pull request's `insert.link` warning note and its history-table row are still in place. No conflict markers are left, and no other file needed a change. The `link`-filtered tests of `wordcraft-engine` and `wordcraft-ui-egui` all passed on the merged tree. I did not run the full test suites, clippy or the format check.
2026-12-04 22:28:48 +00:00
RickiNano 967d608eb5 Links: the link warning applies to every target; the test checks the status repeats it (#8541)
The insert.link params doc put the warning inside the Place in This
Document note, though a URL link gets it too. The two-paragraph test
now checks that the warning is not empty and that the status line
shows the same message, without pinning its wording.
2026-12-04 08:56:21 +01:00
RickiNano 121a43de5b Links: say when Text to display is not applied (#8541)
Ctrl+K on a selection that isn't one plain line (several paragraphs,
a picture or field, a field's result) shows <<Selection in document>>
in Text to display, but the field stays editable. Text typed over it
reached insert.link, which linked the selection with its own text and
reported success, so the edit vanished without a word.

insert.link now notes when a given text differs from the selection
and is not applied: the status line says so and the result carries a
"warning", so the dialog, the CLI and MCP all report it. A text equal
to the selection, or the placeholder the dialog drops, still links
silently.
2026-12-04 07:50:10 +01:00
5 changed files with 28 additions and 5 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ pub fn specs() -> Vec<CommandSpec> {
.then_some("text boxes can't go inside a text box")
}),
CommandSpec::new("insert.link", "Link", "Insert › Links", link).key("Mod+K").params(
r#"{"url": string} | {"bookmark": name} | {"heading": block (see link.targets)} | {"top": true}, "text"?: string (Place in This Document: a bookmark, a heading or the top of the document)"#,
r#"{"url": string} | {"bookmark": name} | {"heading": block (see link.targets)} | {"top": true}, "text"?: string (Place in This Document: a bookmark, a heading or the top of the document); for every target, the result has a "warning" when a selection keeps its own text instead of "text""#,
),
CommandSpec::new("link.targets", "Link", "Insert › Links", link_targets).pure(),
CommandSpec::new("insert.removeLink", "Remove Hyperlink", "Insert › Links", |s, _| super::format::apply(s, &|c| {
+10
View File
@@ -75,11 +75,21 @@ pub(super) fn link(s: &mut Session, v: &Value) -> CmdResult {
s.sel = Selection::caret(end);
s.pending = Some(CharProps::default());
} else {
// A Text to display that differs from the selection but can't retype it is not applied:
// the caller is told so rather than left to think it was (#8541).
let kept = p::str(v, "text").is_some_and(|t| !t.is_empty() && one_line_selection(s) != Some(t) && s.selected_text() != t);
let (a, b) = s.sel.ordered();
s.doc.format_range(&a, &b, &|c| {
c.link = Some(url.clone());
c.style = style.clone();
})?;
if kept {
const KEPT: &str = "Text to display was not applied: the selection is linked with its own text.";
s.status = KEPT.into();
let mut out = sel_result(s)?;
out["warning"] = json!(KEPT);
return Ok(out);
}
}
sel_result(s)
}
+10 -1
View File
@@ -1598,11 +1598,20 @@ fn a_new_selection_drops_the_formatting_left_after_a_link() {
#[test]
fn a_link_over_two_paragraphs_keeps_their_text() {
// Word shows <<Selection in Document>> for such a selection: the text to display is ignored.
// The caller is told the text was not applied, not left to think it was (#8541).
let mut s = typed("one\ntwo");
run(&mut s, "select.all", json!({}));
run(&mut s, "insert.link", json!({"url": "https://example.org/", "text": "both"}));
let r = s.run("insert.link", &json!({"url": "https://example.org/", "text": "both"})).unwrap();
assert_eq!(texts(&s), ["one", "two"]);
assert_eq!(links(&s), [("One".into(), false), ("two".into(), false)]);
let warning = r.get("warning").and_then(|w| w.as_str()).unwrap_or_default();
assert!(!warning.is_empty(), "the result says the text was kept: {r}");
assert_eq!(s.status, warning, "the status line says the same");
// Text to display left as the selection shows it is no change, so there is nothing to report.
let mut s = typed("go see kiln now");
run(&mut s, "select.text", json!({"text": "see"}));
let r = s.run("insert.link", &json!({"url": "https://example.org/", "text": "see"})).unwrap();
assert!(r.get("warning").is_none(), "{r}");
}
#[test]
+2 -1
View File
@@ -97,7 +97,8 @@ fn settle(app: &mut WordApp, _ctx: &egui::Context, id: DialogId) -> Settle {
/// The text Text to display shows: the selected text, or a placeholder when the selection is not
/// plain text in one line of one paragraph (#8286). `insert.link` keeps such a selection as it is,
/// so the placeholder is never written. lean: still editable, craft-libs has no read-only field.
/// so the placeholder is never written. lean: still editable, craft-libs has no read-only field;
/// text typed over the placeholder is not applied, and `insert.link` says so on the status line (#8541).
fn display_text(app: &WordApp) -> String {
if wordcraft_engine::cmd::insert::selection_is_one_line(&app.session) {
app.session.selected_text()
File diff suppressed because one or more lines are too long