Tangent Circle Tool: the radius dialog keeps its preview after a failed OK

OK hands the dialog's live preview a copy to commit, so a draw that is
refused leaves the dialog owning the interaction it started, and Cancel
or a radius with no circle still ends it. New test:
a_failed_ok_keeps_the_preview_for_cancel.

docs/target-app-parity.md and the module doc now say that Auto-Update
Default sets the tool's Shift radius only for a radius from 0.01 to
1,000,000 pt.
This commit is contained in:
dotCooCoo committed 2026-11-25 22:13:31 -08:00
1 parent 97621a10fa
commit 45b671a22b
2 files changed
+37 -4

No files matched your search

@@ -4,7 +4,7 @@
//! nearest the click ([`tangent_circle::radius_circle`]). A radius that gives no circle there shows
//! the tool's note and leaves OK off, as does an edit to either segment after the click. OK draws
//! the circle with `shape.circleThroughPoints` in one undo step, and with Auto-Update Default on
//! also sets the tool's `radius` to the one given; Cancel draws nothing.
//! also sets the tool's `radius` to the one given when it is in the tool's range; Cancel draws nothing.
use craft::ui::contract::Bind;
use craft::ui::dialog::DialogId;
@@ -202,8 +202,8 @@ fn ok(app: &mut VectorcraftApp, result: &ParamResult) -> Result<(), String> {
}
};
let auto = app.session.tool_options_of(tangent_circle::ID).get("autoUpdateDefault").and_then(Value::as_bool) == Some(true);
let preview = std::mem::take(&mut open.preview);
if let Err(e) = preview.commit(app, DRAW, points) {
// A failed commit leaves the interaction running: the dialog keeps its preview, so Cancel still ends it.
if let Err(e) = open.preview.clone().commit(app, DRAW, points) {
app.addon_dialogs.tangent_radius = Some(open);
return Err(e);
}
@@ -382,6 +382,39 @@ mod tests {
assert_eq!(count(&app), paths);
}
#[test]
fn a_failed_ok_keeps_the_preview_for_cancel() {
let mut app = app_with_lines(&[100, 140]);
let (paths, steps) = (count(&app), undo_steps(&app));
click(&mut app, 150.0, 100.0, false);
click(&mut app, 200.0, 140.0, false);
frame(&mut app);
assert_eq!(count(&app), paths + 1);
// The layer the preview started from is locked before OK, so OK's draw is refused and the dialog stays open.
{
let st = app.session.doc_mut().unwrap();
let layer = st.doc.layers[0].id;
let it = st.interaction.as_mut().unwrap();
std::sync::Arc::make_mut(&mut it.doc).node_mut(layer).unwrap().locked = true;
}
let id = dialog_id(&app);
assert!(confirm(&app, id), "OK is on");
frame(&mut app);
assert!(is_open(&app));
assert!(app.session.in_interaction());
// The dialog still owns the interaction: a radius with no circle there ends it.
set(&app, id, "radius", json!(25));
frame(&mut app);
assert_eq!(note(&app).as_deref(), Some(tool::NO_CIRCLE));
assert!(!app.session.in_interaction());
// Cancel closes it with nothing drawn and no undo step.
cancel(&app, id);
frame(&mut app);
assert!(!is_open(&app));
assert!(!app.session.in_interaction());
assert_eq!((count(&app), undo_steps(&app)), (paths, steps));
}
#[test]
fn a_click_found_radius_outside_the_tool_range_can_be_drawn() {
// Lines 2,400,000 pt apart: a click on each finds the circle of radius 1,200,000, past the
+1 -1
View File
@@ -3078,7 +3078,7 @@ A VectorCraft addition, so no area score moves. The Tangent Circle Tool (`tangen
The tool's options dialog also sets the preview and how a segment is picked, the options the help page lists (https://docs.astutegraphics.com/subscribe/tangent-circle-tool): Circle Center and Circle Radii Lines (`center`, `radii`) show or hide the center cross and the radii, Color (`color`: red, blue, magenta, green, black or gray) colors the circle, the cross, the radii and the note, Snap Tolerance (`snapTolerance`, screen pixels) is how near the pointer picks a segment with Smart Guides on, the Smart Guides Snapping Tolerance counting when it is larger, and Snap When Smart Guides Are Off (`snapWithoutGuides`) keeps that reach with Smart Guides off; without it the Selection Tolerance applies. Of the segments within reach the nearest is picked. The defaults (both shown, red, 3 px, snapping on) and the 0 to 25 px range are VectorCraft's own; they are kept with the preferences, and `tool.setOption` gives an error for a value an option does not take. Tests: `addons::tangent_circle::tests` in `vectorcraft-tools` (the preview options, the snapping reach, the options' values) and `the_tangent_circle_options_set_the_preview_and_snapping` in `vectorcraft-ui-egui`.
Ask For Circle Radius and Auto-Update Default (2026-11-20): two options of the tool (`askRadius`, `autoUpdateDefault`, both off to start with). With Ask For Circle Radius on, a click on the second segment that finds a circle, with or without Shift, opens a Tangent Circle dialog at that circle's radius instead of drawing; a drag draws at once. Each radius typed previews the circle of that radius nearest the click, a radius with no circle there, an edit to either segment after the click, or another active document, shows the note and leaves OK off, a target layer that is locked or hidden says so and leaves OK off, a radius typed outside 0.01 to 1,000,000 pt (other than the click's own) shows an error and leaves OK off, OK draws the circle in one undo step, and Cancel draws nothing and keeps the first segment picked. With Auto-Update Default on, OK also makes the radius given the tool's Shift radius. Tests: `ask_for_circle_radius_opens_the_dialog_after_a_click_but_not_after_a_drag` and `the_radius_dialog_knows_when_its_segments_changed` in `vectorcraft-tools`, and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok`, `another_document_or_a_segment_changed_after_the_click_gives_no_circle`, `a_click_found_radius_outside_the_tool_range_can_be_drawn`, `a_circle_the_target_layer_cannot_take_shows_why_and_leaves_ok_off`, `a_switch_to_another_document_leaves_its_interaction_alone`, `a_second_click_replaces_the_open_dialog` and `a_radius_that_is_not_a_number_is_refused_and_keeps_the_circle` in `vectorcraft-ui-egui`.
Ask For Circle Radius and Auto-Update Default (2026-11-20): two options of the tool (`askRadius`, `autoUpdateDefault`, both off to start with). With Ask For Circle Radius on, a click on the second segment that finds a circle, with or without Shift, opens a Tangent Circle dialog at that circle's radius instead of drawing; a drag draws at once. Each radius typed previews the circle of that radius nearest the click, a radius with no circle there, an edit to either segment after the click, or another active document, shows the note and leaves OK off, a target layer that is locked or hidden says so and leaves OK off, a radius typed outside 0.01 to 1,000,000 pt (other than the click's own) shows an error and leaves OK off, OK draws the circle in one undo step, and Cancel draws nothing and keeps the first segment picked. With Auto-Update Default on, OK also makes the radius given the tool's Shift radius when it is from 0.01 to 1,000,000 pt. Tests: `ask_for_circle_radius_opens_the_dialog_after_a_click_but_not_after_a_drag` and `the_radius_dialog_knows_when_its_segments_changed` in `vectorcraft-tools`, and `the_radius_dialog_previews_says_when_there_is_none_cancels_and_draws_on_ok`, `another_document_or_a_segment_changed_after_the_click_gives_no_circle`, `a_failed_ok_keeps_the_preview_for_cancel`, `a_click_found_radius_outside_the_tool_range_can_be_drawn`, `a_circle_the_target_layer_cannot_take_shows_why_and_leaves_ok_off`, `a_switch_to_another_document_leaves_its_interaction_alone`, `a_second_click_replaces_the_open_dialog` and `a_radius_that_is_not_a_number_is_refused_and_keeps_the_circle` in `vectorcraft-ui-egui`.
## Path Precision Tools add-on: Trim at Crossings (2026-11-13)