mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-04 22:49:54 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba887ee766 | ||
|
|
967d608eb5 | ||
|
|
121a43de5b |
@@ -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| {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user