Perspective grid: coming back from a temporary tool keeps a hidden grid hidden (review of #333)

Choosing a perspective tool shows the grid, but the canvas also re-selected the tool after a
Cmd-drag with the borrowed Selection tool, so a grid hidden with the tool chosen came back after
any Cmd-drag. `Session::switch_tool` (and the app's `restore_tool`) switch without choosing; the
temporary-tool return uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-08 03:27:36 +07:00
co-authored by Claude Opus 5.5
parent 4a676c4d5e
commit b6bdef3de6
4 changed files with 36 additions and 3 deletions
+16
View File
@@ -267,6 +267,22 @@ fn the_grid_hides_while_a_perspective_tool_is_chosen() {
}
}
#[test]
fn a_hidden_grid_stays_hidden_back_from_a_temporary_tool() {
// Cmd-dragging with a perspective tool borrows the Selection tool; going back to the
// perspective tool is not choosing it, so the grid hidden meanwhile stays hidden.
let mut s = session();
let v = ViewInfo::default();
s.select_tool("perspectiveGrid", v).unwrap();
s.execute("perspective.grid.show", &json!({"visible": false})).unwrap();
s.switch_tool("selection", v).unwrap();
s.switch_tool("perspectiveGrid", v).unwrap();
assert!(s.overlays(v).is_empty());
s.select_tool("selection", v).unwrap();
s.select_tool("perspectiveGrid", v).unwrap();
assert!(s.overlays(v).len() > 20, "choosing it shows the grid");
}
#[test]
fn grid_preset_and_set_are_undoable() {
let mut s = session();
+7 -1
View File
@@ -56,7 +56,7 @@ impl Session {
self.tool.id()
}
/// Switch tools (finishing any pending tool work first).
/// Choose a tool (the toolbar, its shortcut, MCP), finishing any pending tool work first.
pub fn select_tool(&mut self, id: &str, view: ViewInfo) -> Result<()> {
// Choosing a perspective tool shows the document's perspective grid; Hide Grid hides it
// again, the tool staying chosen.
@@ -65,6 +65,12 @@ impl Session {
{
crate::cmd::distortcmds::silent(self, |g| g.visible = true)?;
}
self.switch_tool(id, view)
}
/// Switch to tool `id` without choosing it afresh (back from a temporary tool: a hidden
/// perspective grid stays hidden), finishing any pending tool work first.
pub fn switch_tool(&mut self, id: &str, view: ViewInfo) -> Result<()> {
if self.tool.id() == id {
return Ok(());
}
+1 -1
View File
@@ -560,7 +560,7 @@ fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, rect:
if matches!(d, Drag::TempSelect | Drag::Art { temp: true })
&& let Some(prev) = ui.data(|dd| dd.get_temp::<String>(temp_tool_id()))
{
app.select_tool(&prev);
app.restore_tool(&prev);
}
}
Drag::Pan { .. } | Drag::RotateView { .. } => {}
+12 -1
View File
@@ -510,8 +510,19 @@ impl VectorcraftApp {
/// Select a tool (also used by the toolbar and shortcuts).
pub fn select_tool(&mut self, id: &str) {
self.change_tool(id, true);
}
/// Go back to tool `id` after a temporary one, without choosing it afresh
/// ([`vectorcraft_engine::Session::switch_tool`]).
pub fn restore_tool(&mut self, id: &str) {
self.change_tool(id, false);
}
fn change_tool(&mut self, id: &str, choose: bool) {
let v = self.view_info();
if let Err(e) = self.session.select_tool(id, v) {
let r = if choose { self.session.select_tool(id, v) } else { self.session.switch_tool(id, v) };
if let Err(e) = r {
self.ui.status = e.to_string();
}
if let Some(g) = vectorcraft_tools::catalog::group_of(id)