Hand the saved shortcut set to the key stage when saved preferences are restored; the selection tool tests draw a frame before editing shortcuts and run each frame's fired commands

This commit is contained in:
bflatastic
2026-11-22 23:10:27 +07:00
parent 2da205e3f2
commit 252767f9b0
3 changed files with 18 additions and 13 deletions
+3 -1
View File
@@ -13,8 +13,10 @@ pub fn snapshot(app: &mut VectorcraftApp) {
app.ui.engine_prefs = app.session.prefs.to_json();
}
/// Restore engine prefs from `UiState` after the host loaded saved UI state.
/// Restore engine prefs from `UiState` after the host loaded saved UI state, and hand its shortcut set to the key
/// stage.
pub fn restore(app: &mut VectorcraftApp) {
crate::shortcut_editor::use_active_set(app);
let mut p: Prefs = serde_json::from_value(app.ui.engine_prefs.clone()).unwrap_or_default();
if app.ui.engine_prefs.is_null() {
// Older preference files: keep the saved brightness.
+1 -1
View File
@@ -1182,7 +1182,7 @@ fn keep(app: &mut VectorcraftApp, keymap: &Keymap) -> Result<(), String> {
/// Hands the set in use to the key stage, each Effect menu item's shortcut under the command its
/// item runs now.
fn use_active_set(app: &mut VectorcraftApp) {
pub(crate) fn use_active_set(app: &mut VectorcraftApp) {
let active = app.ui.shortcut_sets.active_overrides(&BUILTINS);
app.shortcut_overrides = Arc::new(crate::keymap::effect_keys_in(active, &snapshot().effects));
}
+14 -11
View File
@@ -35,13 +35,16 @@ impl Drop for Globals {
}
}
fn app() -> (VectorcraftApp, NodeId) {
/// The app with a rectangle, Selection chosen, shown in a window that has drawn a frame, where shortcuts are edited.
fn app() -> (VectorcraftApp, NodeId, Keyboard) {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300, "profile": null})).unwrap();
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");
(app, id)
let mut keys = Keyboard::new();
keys.frame(&mut app, vec![]);
(app, id, keys)
}
fn path_state(app: &VectorcraftApp, id: NodeId) -> (PathData, Vec<NodeId>, usize) {
@@ -76,6 +79,8 @@ impl Keyboard {
app.ui(ui);
},
);
// The commands the pass fired run as the host's next frame begins.
embed::before_input(&self.ctx, |out| app.frame_input(out));
out.textures_delta.clear();
}
@@ -115,10 +120,9 @@ fn configure_control_backtick(app: &mut VectorcraftApp) {
#[test]
fn selection_tools_existing_v_and_a_defaults_keep_their_choices() {
let _globals = Globals::new();
let (mut app, id) = app();
let (mut app, id, mut keys) = app();
let before = path_state(&app, id);
app.select_tool("pen");
let mut keys = Keyboard::new();
keys.tap(&mut app, Key::V, Modifiers::NONE);
assert_eq!(app.session.tool_id(), "selection");
keys.tap(&mut app, Key::A, Modifiers::NONE);
@@ -129,7 +133,7 @@ fn selection_tools_existing_v_and_a_defaults_keep_their_choices() {
#[test]
fn selection_tools_configured_control_backtick_toggles_both_arrows() {
let _globals = Globals::new();
let (mut app, id) = app();
let (mut app, id, mut keys) = app();
let before = path_state(&app, id);
let rows = app.run("shortcuts.list", json!({"query": SWITCH})).unwrap();
let rows = rows.as_array().unwrap();
@@ -139,7 +143,6 @@ fn selection_tools_configured_control_backtick_toggles_both_arrows() {
assert!(rows[0]["default"].is_null());
assert!(rows[0]["shortcut"].is_null());
configure_control_backtick(&mut app);
let mut keys = Keyboard::new();
keys.tap(&mut app, Key::Backtick, control());
assert_eq!(app.session.tool_id(), "directSelection");
keys.tap(&mut app, Key::Backtick, control());
@@ -150,13 +153,14 @@ fn selection_tools_configured_control_backtick_toggles_both_arrows() {
#[test]
fn selection_tools_saved_binding_runs_and_reset_removes_it() {
let _globals = Globals::new();
let (mut original, _) = app();
let (mut original, _, _) = app();
configure_control_backtick(&mut original);
let saved = serde_json::to_string(&original.ui).unwrap();
let (mut restored, id) = app();
let (mut restored, id, mut keys) = app();
// As the host loads saved preferences: the UI state, then what it restores.
restored.ui = serde_json::from_str::<UiState>(&saved).unwrap();
vectorcraft_ui_egui::prefs_dialog::restore(&mut restored);
let before = path_state(&restored, id);
let mut keys = Keyboard::new();
keys.tap(&mut restored, Key::Backtick, control());
assert_eq!(restored.session.tool_id(), "directSelection");
restored.run("shortcuts.set", json!({"id": SWITCH, "shortcut": null})).unwrap();
@@ -171,7 +175,7 @@ fn selection_tools_saved_binding_runs_and_reset_removes_it() {
#[test]
fn selection_tools_other_tools_enter_selection_and_explicit_choice_survives_release() {
let _globals = Globals::new();
let (mut app, id) = app();
let (mut app, id, mut keys) = app();
let before = path_state(&app, id);
for third in ["pen", "groupSelection"] {
app.select_tool(third);
@@ -182,7 +186,6 @@ fn selection_tools_other_tools_enter_selection_and_explicit_choice_survives_rele
}
configure_control_backtick(&mut app);
app.select_tool("pen");
let mut keys = Keyboard::new();
keys.key(&mut app, Key::V, true, Modifiers::NONE);
assert_eq!(app.session.tool_id(), "selection");
keys.tap(&mut app, Key::Backtick, control());