Merge pull request #10284 from storytold/fix/vectorcraft-0251-mac-undo

Deliver native macOS Undo and Redo shortcuts before their key-up
This commit is contained in:
FredApps authored and GitHub committed 2026-11-30 17:10:35 +01:00
commit ce21d2f626
3 files changed
+27 -2

No files matched your search

+6 -1
View File
@@ -380,7 +380,12 @@ impl VectorcraftApp {
}
/// A window's raw input, before egui and the keys read it (the host's `raw_input_hook`).
pub fn raw_input(&self, ctx: &egui::Context, raw: &mut egui::RawInput) {
pub fn raw_input(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) {
// AppKit consumes the key-down and winit can already have queued its key-up.
// Poll before the runtime orders the press and release in this frame's input.
if let Some(menu) = self.services.native_menu.as_mut() {
menu.poll(ctx);
}
crate::type_editing::keep_layout_text(self, ctx, raw);
}
-1
View File
@@ -27,7 +27,6 @@ pub(crate) fn run(app: &mut VectorcraftApp, ctx: &egui::Context) {
let gate =
Gate::default().modal(app.file_dialog_open()).recording_shortcut(recording_shortcut(app)).text_editing(ctx.egui_wants_keyboard_input());
let Some(menu) = app.services.native_menu.as_mut() else { return };
menu.poll(ctx);
menu.set_gate(gate);
let clicks = menu.take_clicks(ctx);
// A menu opening reads the Scripts folder again.
+21
View File
@@ -458,3 +458,24 @@ fn a_key_equivalent_paste_pastes_a_picture_from_another_app() {
assert_eq!(images(&m), n, "press {n} pastes one picture");
}
}
/// AppKit handles a menu shortcut's key-down before winit delivers the matching key-up.
/// The two must reach the same input batch, even if this frame can have only one pass.
#[test]
fn a_native_undo_and_redo_key_equivalent_each_change_the_canvas_once() {
let mut m = Mac::new(true);
m.ctx.options_mut(|o| o.max_passes = std::num::NonZeroUsize::MIN);
let id = m.app.run("shape.rectangle", json!({"x": 200, "y": 150, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap();
let id = vectorcraft_doc::NodeId(id);
m.frame(vec![]);
for (chord, shift, present) in [("Cmd+Z", false, false), ("Cmd+Shift+Z", true, true)] {
let mut modifiers = if crate::keymap::platform().is_mac() { Modifiers::MAC_CMD } else { Modifiers::CTRL };
modifiers.command = true;
modifiers.shift = shift;
m.fake.report(MenuEvent::Key(Chord::parse(chord).unwrap()));
m.frame(vec![Event::Key { key: Key::Z, physical_key: Some(Key::Z), pressed: false, repeat: false, modifiers }]);
assert_eq!(m.app.session.active().unwrap().doc.node(id).is_some(), present, "{chord} with the native key-up");
m.frame(vec![]);
assert_eq!(m.app.session.active().unwrap().doc.node(id).is_some(), present, "{chord} was applied once");
}
}