From 62729e3a99a3c45dd7ef5fb1f9137167606a2e2c Mon Sep 17 00:00:00 2001 From: Marco Arnulfo Date: Wed, 14 Oct 2026 19:52:30 +0200 Subject: [PATCH] Keyboard: Alt+= no longer starts an edit with the `=` it types (fixes #1327) --- crates/ui-egui/src/grid.rs | 6 +++- crates/ui-egui/tests/keyboard_shortcuts.rs | 33 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index 97b787ef3..0190eacbc 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -2590,6 +2590,9 @@ fn keyboard(app: &mut SheetApp, ctx: &egui::Context, resp: &egui::Response, geo: if !m.alt && (m.ctrl || m.command || (m.shift && *key == egui::Key::Space))) }); let page = ((geo.cells.height() / geo.z) / sh.default_row_height).floor().max(1.0) as i64; + // Alt shortcuts type their character too on Windows and Linux (Alt+= sends Text("=")): once + // a shortcut ran, that text must not start an edit over what it just did. + let mut shortcut_ran = false; for ev in events { match ev { egui::Event::Copy => { @@ -2599,7 +2602,7 @@ fn keyboard(app: &mut SheetApp, ctx: &egui::Context, resp: &egui::Response, geo: app.copy_to_clipboard(ctx, "edit.cut"); } egui::Event::Paste(text) => app.paste_external(text), - egui::Event::Text(_) if shortcut_pressed => {} + egui::Event::Text(_) if shortcut_pressed || shortcut_ran => {} egui::Event::Text(text) if text.chars().all(|c| !c.is_control()) && !text.is_empty() => { app.begin_edit(Some(text), false); if let Some(ed) = app.editor.as_mut() { @@ -2610,6 +2613,7 @@ fn keyboard(app: &mut SheetApp, ctx: &egui::Context, resp: &egui::Response, geo: egui::Event::Key { key, physical_key, pressed: true, modifiers: m, .. } => { use egui::Key; if crate::keymap::dispatch(app, ctx, key, physical_key, m, geo, sh) { + shortcut_ran = true; continue; } let cmd = m.command; diff --git a/crates/ui-egui/tests/keyboard_shortcuts.rs b/crates/ui-egui/tests/keyboard_shortcuts.rs index c0a1307b3..78bc966f5 100644 --- a/crates/ui-egui/tests/keyboard_shortcuts.rs +++ b/crates/ui-egui/tests/keyboard_shortcuts.rs @@ -214,3 +214,36 @@ fn alt_down_only_opens_enabled_table_filter_buttons() { assert_eq!(h.state().session.active().unwrap().selection.active.a1(), "B1"); } } + +/// Alt+= as Windows and Linux report it: the key press, then the `=` the OS types with it. +fn alt_equals(h: &mut Harness) { + h.input_mut().events.push(Event::Key { + key: Key::Equals, + physical_key: Some(Key::Equals), + pressed: true, + repeat: false, + modifiers: Modifiers::ALT, + }); + h.input_mut().events.push(Event::Text("=".into())); + h.run_steps(2); +} + +#[test] +fn alt_equals_autosum_does_not_also_type_the_equals_sign() { + let input = |h: &Harness, a1: &str| h.state().session.active().unwrap().wb.active().unwrap().input_text(CellRef::parse(a1).unwrap()); + // Column above, row to the left, and a block (totals below each column). + for (selected, cell, formula) in [("A4", "A4", "=SUM(A1:A3)"), ("C3", "C3", "=SUM(A3:B3)"), ("A1:B3", "B4", "=SUM(B1:B3)")] { + let mut h = harness(book(selected)); + alt_equals(&mut h); + assert_eq!(input(&h, cell), formula, "Alt+= on {selected}"); + assert!(h.state().editor.is_none(), "Alt+= on {selected} started an edit"); + // Enter moves on: there is no stray `=` edit to commit. + key(&mut h, Key::Enter, Modifiers::NONE); + assert!(h.state().message.is_none(), "Alt+= on {selected}: {:?}", h.state().message); + assert_eq!(input(&h, cell), formula); + } + // Nothing to sum: AutoSum's own edit, `=SUM()`, not `=`. + let mut h = harness(book("E10")); + alt_equals(&mut h); + assert_eq!(h.state().editor.as_ref().map(|e| e.text.clone()).as_deref(), Some("=SUM()")); +}