From 0c58dc5ec67207e4da4fe78b5945279657ef8ebf Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 21 Nov 2026 23:25:45 +0700 Subject: [PATCH] shortcuts-w12: net change of 1 commits - shortcuts-w12: written from its sheet --- crates/ui-egui/src/tests/distortkeys.rs | 40 ++++++++----------- crates/ui-egui/src/tests/selectescape.rs | 7 ++-- crates/ui-egui/src/tests/toolescape.rs | 7 ++-- .../ui-egui/tests/selection_tools_toggle.rs | 16 +++----- 4 files changed, 29 insertions(+), 41 deletions(-) diff --git a/crates/ui-egui/src/tests/distortkeys.rs b/crates/ui-egui/src/tests/distortkeys.rs index 63edd04667..cca2c13e9f 100644 --- a/crates/ui-egui/src/tests/distortkeys.rs +++ b/crates/ui-egui/src/tests/distortkeys.rs @@ -8,6 +8,7 @@ use serde_json::{Value, json}; use vectorcraft_engine::Session; use vectorcraft_tools::{PointerEvent, PointerKind}; +use super::synthetic::key_frame; use crate::VectorcraftApp; /// A 300×300 document with a selected 10 pt line from (100, 200) to (300, 200) → its id. @@ -20,12 +21,12 @@ fn app_with_line() -> (VectorcraftApp, u64) { (app, id) } -/// One frame pressing `key` through the shortcut handler. +/// One app frame pressing `key`, after an empty frame that builds the board's keymap. fn press(app: &mut VectorcraftApp, key: Key) { let ctx = egui::Context::default(); + key_frame(app, &ctx, vec![]); let ev = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; - let mut out = ctx.run_ui(egui::RawInput { events: vec![ev], ..Default::default() }, |ui| crate::shortcuts::handle(app, ui.ctx())); - out.textures_delta.clear(); + key_frame(app, &ctx, vec![ev]); } #[test] @@ -216,23 +217,17 @@ fn protected_artboard_key(key: Key) { } #[test] -fn artboard_keys_delete_keeps_first_of_all_selected_boards() { - delete_artboards_with_key(Key::Delete, true); +fn artboard_keys_keep_first_of_all_selected_boards() { + for key in [Key::Delete, Key::Backspace] { + delete_artboards_with_key(key, true); + } } #[test] -fn artboard_keys_backspace_keeps_first_of_all_selected_boards() { - delete_artboards_with_key(Key::Backspace, true); -} - -#[test] -fn artboard_keys_delete_protects_last_board_and_art() { - protected_artboard_key(Key::Delete); -} - -#[test] -fn artboard_keys_backspace_protects_last_board_and_art() { - protected_artboard_key(Key::Backspace); +fn artboard_keys_protect_last_board_and_art() { + for key in [Key::Delete, Key::Backspace] { + protected_artboard_key(key); + } } fn delete_artboards_with_key(key: Key, select_all: bool) { @@ -272,13 +267,10 @@ fn delete_artboards_with_key(key: Key, select_all: bool) { } #[test] -fn artboard_keys_delete_removes_partial_selection_in_one_step() { - delete_artboards_with_key(Key::Delete, false); -} - -#[test] -fn artboard_keys_backspace_removes_partial_selection_in_one_step() { - delete_artboards_with_key(Key::Backspace, false); +fn artboard_keys_remove_partial_selection_in_one_step() { + for key in [Key::Delete, Key::Backspace] { + delete_artboards_with_key(key, false); + } } /// Keyboard-only history sequences must not need a canvas event to align the navigator and tool. diff --git a/crates/ui-egui/src/tests/selectescape.rs b/crates/ui-egui/src/tests/selectescape.rs index 1acf599f72..992d10bf36 100644 --- a/crates/ui-egui/src/tests/selectescape.rs +++ b/crates/ui-egui/src/tests/selectescape.rs @@ -5,14 +5,15 @@ use serde_json::json; use vectorcraft_engine::Session; use vectorcraft_tools::{Mods, PointerEvent, PointerKind}; +use super::synthetic::key_frame; use crate::VectorcraftApp; -/// One frame pressing `key` through the shortcut handler. +/// One app frame pressing `key`, after an empty frame that builds the board's keymap. fn press(app: &mut VectorcraftApp, key: Key) { let ctx = egui::Context::default(); + key_frame(app, &ctx, vec![]); let ev = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; - let mut out = ctx.run_ui(egui::RawInput { events: vec![ev], ..Default::default() }, |ui| crate::shortcuts::handle(app, ui.ctx())); - out.textures_delta.clear(); + key_frame(app, &ctx, vec![ev]); } #[test] diff --git a/crates/ui-egui/src/tests/toolescape.rs b/crates/ui-egui/src/tests/toolescape.rs index b3012bb636..9652dbcd5b 100644 --- a/crates/ui-egui/src/tests/toolescape.rs +++ b/crates/ui-egui/src/tests/toolescape.rs @@ -6,14 +6,15 @@ use serde_json::json; use vectorcraft_engine::Session; use vectorcraft_tools::{PointerEvent, PointerKind}; +use super::synthetic::key_frame; use crate::VectorcraftApp; -/// One frame pressing `key` through the shortcut handler. +/// One app frame pressing `key`, after an empty frame that builds the board's keymap. fn press(app: &mut VectorcraftApp, key: Key) { let ctx = egui::Context::default(); + key_frame(app, &ctx, vec![]); let ev = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; - let mut out = ctx.run_ui(egui::RawInput { events: vec![ev], ..Default::default() }, |ui| crate::shortcuts::handle(app, ui.ctx())); - out.textures_delta.clear(); + key_frame(app, &ctx, vec![ev]); } #[test] diff --git a/crates/ui-egui/tests/selection_tools_toggle.rs b/crates/ui-egui/tests/selection_tools_toggle.rs index fa9793fe59..e897160851 100644 --- a/crates/ui-egui/tests/selection_tools_toggle.rs +++ b/crates/ui-egui/tests/selection_tools_toggle.rs @@ -9,31 +9,27 @@ use serde_json::json; use vectorcraft_doc::NodeId; use vectorcraft_engine::Session; use vectorcraft_geom::PathData; -use vectorcraft_ui_egui::{UiState, VectorcraftApp, i18n, shortcut_editor, shortcuts}; +use vectorcraft_ui_egui::{UiState, VectorcraftApp, i18n}; const SWITCH: &str = "tool.switchSelectionTools"; static CASE: Mutex<()> = Mutex::new(()); -// Integration binaries use process-wide locale/keymap mirrors. Every case owns the guard, -// starts from the same neutral keymap, and restores that keymap even if an assertion fails. +// Integration binaries use a process-wide locale. Every case owns the guard and restores the +// language even if an assertion fails. struct Globals { _lock: MutexGuard<'static, ()>, language: i18n::Lang, - neutral: UiState, } impl Globals { fn new() -> Self { let lock = CASE.lock().unwrap_or_else(|e| e.into_inner()); let language = i18n::current(); - let neutral = UiState::default(); i18n::set_current(i18n::Lang::EN); - shortcut_editor::sync(&neutral); - Self { _lock: lock, language, neutral } + Self { _lock: lock, language } } } impl Drop for Globals { fn drop(&mut self) { - shortcut_editor::sync(&self.neutral); i18n::set_current(self.language); } } @@ -44,7 +40,6 @@ fn app() -> (VectorcraftApp, NodeId) { let shape = app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap(); let id = NodeId(shape["id"].as_u64().unwrap()); app.select_tool("selection"); - shortcut_editor::sync(&app.ui); (app, id) } @@ -74,7 +69,7 @@ impl Keyboard { }, |ui| { app.logic(ui.ctx()); - shortcuts::handle(app, ui.ctx()); + app.ui(ui); }, ); out.textures_delta.clear(); @@ -156,7 +151,6 @@ fn selection_tools_saved_binding_runs_and_reset_removes_it() { let saved = serde_json::to_string(&original.ui).unwrap(); let (mut restored, id) = app(); restored.ui = serde_json::from_str::(&saved).unwrap(); - shortcut_editor::sync(&restored.ui); let before = path_state(&restored, id); let mut keys = Keyboard::new(); keys.tap(&mut restored, Key::Backtick, control());