mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-01 18:26:05 -06:00
Stack on #1332: Alt+= no longer starts an edit with the = it types
This commit is contained in:
@@ -2622,6 +2622,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 => {
|
||||
@@ -2631,7 +2634,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() {
|
||||
@@ -2642,6 +2645,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;
|
||||
|
||||
@@ -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()"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user