Merge pull request #9412 from dotCooCoo/fix/missing-font-cancel-clears-edit

Type: cancelling the missing-font prompt clears the pending edit
This commit is contained in:
BFlat authored and GitHub committed 2026-11-26 23:17:19 +07:00
commit b6cfb0bc91
4 files changed
+36 -16

No files matched your search

+1
View File
@@ -232,6 +232,7 @@ impl VectorcraftApp {
shortcuts_dialog: None,
shortcut_overrides: Default::default(),
told: Default::default(),
missing_font_edit_token: None,
held: Default::default(),
edit_scopes: Default::default(),
command_dialog: Default::default(),
+13
View File
@@ -3599,7 +3599,10 @@ fn double_clicking_type_in_a_missing_font_asks_before_editing() {
// Cancel: nothing is edited, and the document, its undo history and the selection stay.
let (before, undo, selected) =
(node(&app), app.session.doc().unwrap().history.undo.len(), app.session.active().unwrap().selection.objects.clone());
let cancelled_token = app.missing_font_edit_token.expect("the question's edit token");
answer(&mut app, false);
// A delayed approval for the cancelled question can no longer start an edit.
app.session.set_tool_option("missingFontEdit", &json!({"token": cancelled_token, "ok": true}));
timed(&mut app, 1.5, vec![]);
assert_eq!(app.session.tool_options()["editing"], json!(null));
assert!(!app.session.tool_wants_text());
@@ -3609,6 +3612,16 @@ fn double_clicking_type_in_a_missing_font_asks_before_editing() {
// A new double-click asks again; OK edits with the caret where the type was clicked.
double_click(&mut app, 3.0);
assert!(asking(&app), "asked again");
let replaced_token = app.missing_font_edit_token;
// A Type press sent through automation can replace the prompt before the user answers.
let view = app.view_info();
let point = Point::new(b.x0 + b.width() * 0.25, b.center().y);
for kind in [PointerKind::Down, PointerKind::Up] {
crate::canvas::dispatch(&mut app, &PointerEvent::new(kind, point.x, point.y), view);
}
assert_ne!(app.missing_font_edit_token, replaced_token);
crate::dialogs::host::pump(&mut app, &ctx);
assert!(asking(&app), "the replacement question is open");
answer(&mut app, true);
timed(&mut app, 3.5, vec![]);
assert!(!asking(&app));
+20 -16
View File
@@ -100,8 +100,7 @@ wrapped_dialog!(Question, StandardPrompt, KIND);
pub(crate) struct Message(HostedAlert);
wrapped_dialog!(Message, HostedAlert, MESSAGE);
/// The Type tool's question whether to edit type set in fonts that aren't available; its tag is the
/// tool's edit token.
/// The Type tool's question whether to edit type set in fonts that aren't available.
pub(crate) struct MissingFontQuestion(StandardPrompt);
wrapped_dialog!(MissingFontQuestion, StandardPrompt, MISSING_FONT_EDIT);
@@ -215,13 +214,15 @@ pub(crate) fn ask_replace_files(app: &mut VectorcraftApp, doc: u64, files: &[Str
/// While another dialog is open (a press sent with `ui.pointer` reaches the tool then), that dialog
/// stays and the Type tool forgets the edit, as Cancel would.
pub(crate) fn ask_missing_font_edit(app: &mut VectorcraftApp, p: &Value) {
let token = p.get("token").cloned().unwrap_or(Value::Null);
let Some(token) = p.get("token").and_then(Value::as_u64) else {
return;
};
let Some(dialogs) = app.dialogs() else {
answer_missing_font_edit(app, &token, false);
answer_missing_font_edit(app, token, false);
return;
};
if app.any_dialog_open() && !dialogs.with(|host| host.is_open::<MissingFontQuestion>()) {
answer_missing_font_edit(app, &token, false);
answer_missing_font_edit(app, token, false);
return;
}
let names = |k: &str| p.get(k).and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_str).map(str::to_string).collect::<Vec<_>>();
@@ -234,14 +235,18 @@ pub(crate) fn ask_missing_font_edit(app: &mut VectorcraftApp, p: &Value) {
let prompt = StandardPrompt::custom(tl!("Edit type set in fonts that aren't available?"))
.paragraph(detail)
.button(PromptChoice::Proceed, tl!("OK"))
.button(PromptChoice::Cancel, tl!("Cancel"))
.tag(token);
dialogs.with(|host| host.open(MissingFontQuestion(prompt)));
.button(PromptChoice::Cancel, tl!("Cancel"));
dialogs.with(|host| {
host.open(MissingFontQuestion(prompt));
// Replacing a prompt leaves its Cancel in the host. The tool is already waiting on the new token.
let _ = host.take::<MissingFontQuestion>();
});
app.missing_font_edit_token = Some(token);
}
/// Give the Type tool the answer to [`ask_missing_font_edit`]'s question about the edit `token`
/// names: with `ok` the edit starts at once; without, the tool forgets it.
pub(crate) fn answer_missing_font_edit(app: &mut VectorcraftApp, token: &Value, ok: bool) {
fn answer_missing_font_edit(app: &mut VectorcraftApp, token: u64, ok: bool) {
app.session.set_tool_option("missingFontEdit", &json!({"token": token, "ok": ok}));
if ok {
let r = app.session.tool_poll(app.view_info(), false);
@@ -277,13 +282,12 @@ pub(crate) fn pump_missing_font(app: &mut VectorcraftApp, _ctx: &Context) {
let Some(dialogs) = app.dialogs() else {
return;
};
let (ok, token) = match dialogs.with(|host| host.take::<MissingFontQuestion>()) {
None => return,
Some(DialogResult::Ok(mut answer)) => (answer.choice == PromptChoice::Proceed, answer.take_tag::<Value>()),
// PLAN: a question the host cancelled carries no tag, so the tool's token is unknown here.
Some(_) => (false, None),
};
answer_missing_font_edit(app, &token.unwrap_or(Value::Null), ok);
if let Some(result) = dialogs.with(|host| host.take::<MissingFontQuestion>())
&& let Some(token) = app.missing_font_edit_token.take()
{
let ok = matches!(result, DialogResult::Ok(answer) if answer.choice == PromptChoice::Proceed);
answer_missing_font_edit(app, token, ok);
}
}
/// The confirmation open now, if one is: its message and detail as shown, and the command OK runs.
+2
View File
@@ -266,6 +266,8 @@ pub struct VectorcraftApp {
pub(crate) shortcut_overrides: Arc<craft::keymap::Overrides>,
/// Messages waiting for the dialog that shows them.
pub(crate) told: dialogs::host::Told,
/// The Type tool's pending edit, kept even when the dialog closes without a prompt answer.
pub(crate) missing_font_edit_token: Option<u64>,
/// The hosted dialogs whose OK the app answers, one record each.
pub(crate) held: dialogs::host::Held,
/// The undo step each value gesture in progress edits under: a scrub or a slider drag is one