diff --git a/crates/ui-egui/src/grid/keyboard.rs b/crates/ui-egui/src/grid/keyboard.rs index a852d04c3..92dc9034a 100644 --- a/crates/ui-egui/src/grid/keyboard.rs +++ b/crates/ui-egui/src/grid/keyboard.rs @@ -146,7 +146,9 @@ pub(super) fn keyboard(app: &mut SheetApp, ctx: &egui::Context, resp: &egui::Res // Ctrl+Shift+letter (⌘⇧letter) runs the macro with that shortcut, unless GridCraft uses it. _ if cmd && shift && !m.alt && crate::macro_ui::run_shortcut(app, key) => {} _ if cmd && !crate::keymap::altgr_text(ctx, m, ctx.os() == egui::os::OperatingSystem::Mac) => { - crate::ribbon::shortcut(app, key, m) + // The same key the English table reads: Ctrl+Shift+, typing `;` is Ctrl+;. + let (key, shift) = crate::keymap::us_key(key, physical_key, shift).unwrap_or((key, shift)); + crate::ribbon::shortcut(app, key, egui::Modifiers { shift, ..m }); } _ => {} } diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs index 5acce9b4d..462d4cf4d 100644 --- a/crates/ui-egui/src/keymap.rs +++ b/crates/ui-egui/src/keymap.rs @@ -55,14 +55,54 @@ fn borders(preset: &str) -> Shortcut { Shortcut::Run("home.borders", json!({"preset": preset})) } -/// The shortcut for a key press in the grid, if any. `physical` is the key's position on a US -/// layout (as Excel matches Ctrl+Shift+4 rather than the `$` character); `mac` selects the Excel -/// for Mac variants where they differ. Navigation keys go by the logical key: with Num Lock off -/// the numpad's arrows and Page Down report the digit keys (Num6, Num3) as their physical keys. -pub fn lookup(key: Key, physical: Option, m: Modifiers, mac: bool) -> Option { +/// Navigation keys go by the logical key: with Num Lock off the numpad's arrows and Page Down +/// report the digit keys (Num6, Num3) as their physical keys. +fn is_navigation(key: Key) -> bool { use Key::*; - let navigation = matches!(key, ArrowLeft | ArrowRight | ArrowUp | ArrowDown | PageUp | PageDown | Home | End | Insert | Delete); - let key = if navigation { key } else { physical.unwrap_or(key) }; + matches!(key, ArrowLeft | ArrowRight | ArrowUp | ArrowDown | PageUp | PageDown | Home | End | Insert | Delete) +} + +/// The US key and Shift state a symbol or digit key press stands for in the English shortcuts. +/// Digits go by position (Ctrl+Shift+4 is the currency format wherever `$` is). Punctuation keys +/// go by the character the layout types, as Excel does: Shift+, types `;` on a Croatian or German +/// keyboard, so Ctrl+Shift+, is Ctrl+; (today's date) there, and a lone `+` is the US Shift+=. +/// A character egui has no key for (`č`, `ö`, `<`) arrives as the key's position, which stands +/// in. `None` for every other key (letters, navigation, function keys). +pub fn us_key(key: Key, physical: Option, shift: bool) -> Option<(Key, bool)> { + use Key::*; + if is_navigation(key) { + return None; + } + let at = physical?; + let symbol = + |k: Key| matches!(k, Backtick | Minus | Equals | OpenBracket | CloseBracket | Backslash | Semicolon | Quote | Comma | Period | Slash); + match at { + Num0 | Num1 | Num2 | Num3 | Num4 | Num5 | Num6 | Num7 | Num8 | Num9 => Some((at, shift)), + _ if symbol(at) => Some(match key { + // Characters a US keyboard types with Shift. + Colon => (Semicolon, true), + Plus => (Equals, true), + Questionmark => (Slash, true), + Pipe => (Backslash, true), + OpenCurlyBracket => (OpenBracket, true), + CloseCurlyBracket => (CloseBracket, true), + // An unshifted US character, typed here with or without Shift. + _ if key != at && symbol(key) => (key, false), + _ => (key, shift), + }), + _ => None, + } +} + +/// The shortcut for a key press in the grid, if any. `physical` is the key's position on a US +/// layout: digits and letters go by it, punctuation by the character typed ([`us_key`]). `mac` +/// selects the Excel for Mac variants where they differ. Navigation keys go by the logical key. +pub fn lookup(key: Key, physical: Option, m: Modifiers, mac: bool) -> Option { + let (key, shift) = match us_key(key, physical, m.shift) { + Some(us) => us, + None if is_navigation(key) => (key, m.shift), + None => (physical.unwrap_or(key), m.shift), + }; let ctx = LookupContext { key, modifiers: m, @@ -71,7 +111,7 @@ pub fn lookup(key: Key, physical: Option, m: Modifiers, mac: bool) -> Optio alt: m.alt && !m.ctrl && !m.command, ctrl_alt: m.alt && (m.ctrl || m.command), plain: !m.ctrl && !m.command && !m.alt, - shift: m.shift, + shift, mac, }; lookup_number_formats(ctx) diff --git a/crates/ui-egui/src/ribbon/shortcuts.rs b/crates/ui-egui/src/ribbon/shortcuts.rs index cd862cbd9..2a2d3caec 100644 --- a/crates/ui-egui/src/ribbon/shortcuts.rs +++ b/crates/ui-egui/src/ribbon/shortcuts.rs @@ -70,7 +70,8 @@ pub fn shortcut(app: &mut SheetApp, key: Key, m: Modifiers) { None } }, - Key::Semicolon => { + // Ctrl+Shift+; (the time) is in `keymap::lookup`; Cmd+Shift+; on a Mac does nothing. + Key::Semicolon if !shift => { // Insert today's date. let text = app .session diff --git a/crates/ui-egui/tests/it/keyboard_shortcuts.rs b/crates/ui-egui/tests/it/keyboard_shortcuts.rs index f59504dee..4f45bcb03 100644 --- a/crates/ui-egui/tests/it/keyboard_shortcuts.rs +++ b/crates/ui-egui/tests/it/keyboard_shortcuts.rs @@ -212,6 +212,144 @@ fn alt_down_only_opens_enabled_table_filter_buttons() { } } +/// A key press as a non-US layout reports it: `typed` is the character the layout types (egui's +/// logical key), `at` the key's position named after a US keyboard. +fn key_on_layout(h: &mut Harness, typed: Key, at: Key, m: Modifiers) { + h.input_mut().events.push(Event::Key { key: typed, physical_key: Some(at), pressed: true, repeat: false, modifiers: m }); + h.input_mut().events.push(Event::Key { key: typed, physical_key: Some(at), pressed: false, repeat: false, modifiers: m }); + h.run_steps(2); +} + +fn editor_text(h: &Harness) -> Option { + h.state().editor.as_ref().map(|e| e.text.clone()) +} + +fn today(h: &Harness) -> String { + let d = h.state().session.active().unwrap(); + let now = gridcraft_engine::core::date::serial_in_system(d.wb.date_system, gridcraft_engine::calc::now_serial()); + gridcraft_engine::display::format(&gridcraft_engine::core::Value::Number(now.floor()), "m/d/yyyy", &d.wb).text +} + +#[test] +fn symbol_shortcuts_follow_the_character_the_layout_types() { + // Croatian and German keyboards type `;` with Shift+, and `:` with Shift+. (US positions). + // `+` is unshifted, on the US `=` key (Croatian) or `]` key (German); `'` is the US `-` key + // (Croatian) or Shift+# on the US `\` key (German); Shift+0 types `=` on both. + for (layout, plus_at, quote_at, quote_shift) in [("hr", Key::Equals, Key::Minus, false), ("de", Key::CloseBracket, Key::Backslash, true)] { + let mut h = harness(book("C2")); + let size = style(&h, "C2").font.size; + // Ctrl+; (Ctrl+Shift+,): today's date, not Decrease Font Size. + key_on_layout(&mut h, Key::Semicolon, Key::Comma, CTRL_SHIFT); + assert_eq!(editor_text(&h), Some(today(&h)), "{layout}: Ctrl+;"); + assert_eq!(style(&h, "C2").font.size, size, "{layout}: Ctrl+; changed the font size"); + key(&mut h, Key::Escape, Modifiers::NONE); + // Ctrl+: (Ctrl+Shift+.): the time, not Increase Font Size. + key_on_layout(&mut h, Key::Colon, Key::Period, CTRL_SHIFT); + let time = editor_text(&h).unwrap_or_default(); + assert!(time.contains(':') && (time.ends_with("AM") || time.ends_with("PM")), "{layout}: Ctrl+: gave {time:?}"); + assert_eq!(style(&h, "C2").font.size, size, "{layout}: Ctrl+: changed the font size"); + key(&mut h, Key::Escape, Modifiers::NONE); + // Ctrl+': the formula of the cell above. + key_on_layout(&mut h, Key::Quote, quote_at, if quote_shift { CTRL_SHIFT } else { CTRL }); + assert_eq!(editor_text(&h).as_deref(), Some("=A1*2"), "{layout}: Ctrl+'"); + key(&mut h, Key::Escape, Modifiers::NONE); + // Ctrl++: Insert, as Ctrl+Shift+= on a US keyboard. + key_on_layout(&mut h, Key::Plus, plus_at, CTRL); + assert_eq!(h.state().dialog.as_ref().map(|d| d.name()), Some("insertCells"), "{layout}: Ctrl++"); + h.state_mut().dialog = None; + // Digits go by position: Ctrl+Shift+0 unhides columns although it types `=`. + h.state_mut().session.run("selection.set", json!({"range": "B:B"})).unwrap(); + h.state_mut().session.run("home.hideColumns", json!({})).unwrap(); + h.state_mut().session.run("selection.set", json!({"range": "A1:C1"})).unwrap(); + key_on_layout(&mut h, Key::Equals, Key::Num0, CTRL_SHIFT); + assert!(h.state().dialog.is_none(), "{layout}: Ctrl+Shift+0 opened {:?}", h.state().dialog.as_ref().map(|d| d.name())); + let d = h.state().session.active().unwrap(); + assert!(!d.wb.active().unwrap().is_col_hidden(1), "{layout}: Ctrl+Shift+0 didn't unhide column B"); + } +} + +#[test] +fn date_and_time_shortcuts_on_azerty_and_czech_keyboards() { + // French AZERTY types `;` and `:` unshifted on the US `,` and `.` keys; Czech QWERTZ types `;` + // unshifted on the US backtick key and `:` with Shift+. (US positions). + for (layout, semi_at, semi_m, colon_m) in [("fr", Key::Comma, CTRL, CTRL), ("cs", Key::Backtick, CTRL, CTRL_SHIFT)] { + let mut h = harness(book("C2")); + let size = style(&h, "C2").font.size; + key_on_layout(&mut h, Key::Semicolon, semi_at, semi_m); + assert_eq!(editor_text(&h), Some(today(&h)), "{layout}: Ctrl+;"); + key(&mut h, Key::Escape, Modifiers::NONE); + key_on_layout(&mut h, Key::Colon, Key::Period, colon_m); + let time = editor_text(&h).unwrap_or_default(); + assert!(time.contains(':') && (time.ends_with("AM") || time.ends_with("PM")), "{layout}: Ctrl+: gave {time:?}"); + assert_eq!(style(&h, "C2").font.size, size, "{layout}: the font size changed"); + } +} + +#[test] +fn layout_keys_type_their_character_in_a_cell_being_edited() { + // While a cell is edited the grid reads no shortcuts, so `;` and `:` (Shift+, and Shift+. on + // Croatian and German keyboards) are typed, and nothing changes the font size. + let mut h = harness(book("C2")); + let size = style(&h, "C2").font.size; + h.input_mut().events.push(Event::Text("x".into())); + h.run_steps(2); + for (typed, at, text) in [(Key::Semicolon, Key::Comma, ";"), (Key::Colon, Key::Period, ":")] { + let m = Modifiers::SHIFT; + h.input_mut().events.push(Event::Key { key: typed, physical_key: Some(at), pressed: true, repeat: false, modifiers: m }); + h.input_mut().events.push(Event::Text(text.into())); + h.input_mut().events.push(Event::Key { key: typed, physical_key: Some(at), pressed: false, repeat: false, modifiers: m }); + h.run_steps(2); + } + assert_eq!(editor_text(&h).as_deref(), Some("x;:")); + assert_eq!(style(&h, "C2").font.size, size); +} + +#[test] +fn us_symbol_shortcuts_keep_their_keys() { + let mut h = harness(book("C2")); + // Ctrl+;: the date. Ctrl+Shift+; arrives as `:` on Windows and as `;` with Shift elsewhere. + key(&mut h, Key::Semicolon, CTRL); + assert_eq!(editor_text(&h), Some(today(&h))); + key(&mut h, Key::Escape, Modifiers::NONE); + for typed in [Key::Colon, Key::Semicolon] { + key_on_layout(&mut h, typed, Key::Semicolon, CTRL_SHIFT); + assert!(editor_text(&h).is_some_and(|t| t.ends_with("AM") || t.ends_with("PM")), "Ctrl+Shift+; as {typed:?}"); + key(&mut h, Key::Escape, Modifiers::NONE); + } + // Ctrl+Shift+, and Ctrl+Shift+. (`<` and `>` have no egui key) change the font size. + let size = style(&h, "C2").font.size; + key(&mut h, Key::Period, CTRL_SHIFT); + assert!(style(&h, "C2").font.size > size); + key(&mut h, Key::Comma, CTRL_SHIFT); + assert_eq!(style(&h, "C2").font.size, size); + // Ctrl+Shift+= arrives as `+`: Insert. + key_on_layout(&mut h, Key::Plus, Key::Equals, CTRL_SHIFT); + assert_eq!(h.state().dialog.as_ref().map(|d| d.name()), Some("insertCells")); + let run = |id: &'static str| Some(Shortcut::Run(id, json!({}))); + // The lookup itself: `;` typed with Shift is Ctrl+; (handled with the Ctrl letters), not the + // key's position (Decrease Font Size). + assert_eq!(lookup(Key::Semicolon, Some(Key::Comma), CTRL_SHIFT, false), None); + assert_eq!(lookup(Key::Colon, Some(Key::Period), CTRL_SHIFT, false), Some(Shortcut::Time)); + assert_eq!(lookup(Key::Comma, Some(Key::Comma), CTRL_SHIFT, false), run("home.decreaseFontSize")); + // A character egui has no key for (`č` on the US `;` key) leaves the position. + assert_eq!(lookup(Key::Semicolon, Some(Key::Semicolon), CTRL_SHIFT, false), Some(Shortcut::Time)); +} + +#[test] +fn cmd_shift_semicolon_on_a_mac_does_not_insert_the_date() { + // The Mac table has Cmd+; (the time) and Control+; (the date), and nothing for Cmd+Shift+;. It + // arrives as `:` on the US `;` key, or on the US `.` key of a Croatian or German keyboard. + let mut h = harness(book("C2")); + h.ctx.set_os(egui::os::OperatingSystem::Mac); + let cmd_shift = Modifiers { shift: true, mac_cmd: true, command: true, ..Modifiers::NONE }; + for at in [Key::Semicolon, Key::Period] { + key_on_layout(&mut h, Key::Colon, at, cmd_shift); + assert_eq!(editor_text(&h), None, "Cmd+Shift+; at {at:?}"); + } + key(&mut h, Key::Semicolon, Modifiers { mac_cmd: true, command: true, ..Modifiers::NONE }); + assert!(editor_text(&h).is_some_and(|t| t.ends_with("AM") || t.ends_with("PM")), "Cmd+; is still the time"); +} + /// #1443: Ctrl+Q (also with Shift or Alt, which is what AltGr+Q reports on Windows) must not /// close the window and lose unsaved input; macOS keeps Cmd+Q as the app's Quit. #[test] diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 2c1e24a0c..a1debf5fb 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-05 · **Change:** minor (preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-05 · **Change:** minor (punctuation shortcuts follow the keyboard layout's characters; earlier: preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Interaction, controls and feel, against Excel. Part of [target-app-parity.md](target-app-parity.md). **UI/UX fidelity: ~55% ready, 50–80 h** (estimated). Ribbon command coverage is measured @@ -105,6 +105,9 @@ Checked against Microsoft's published "Keyboard shortcuts in Excel" (Windows and `keymap.rs` (everything added in #110, with a `lookup` table that tests cover) and `formula_bar.rs` (keys while editing). "Ctrl" means Cmd on a Mac unless the Mac column says otherwise. Number-format and border keys match the physical key (Ctrl+Shift+4, wherever `$` is). +Punctuation keys go by the character the keyboard layout types, as in Excel: on a Croatian or German +keyboard Ctrl+Shift+, types `;` and inserts the date, Ctrl+Shift+. (`:`) the time, Ctrl++ opens Insert. +A character egui has no key for (`č`, `ö`, `<`) falls back to the key's position. | Shortcut (Windows) | Mac | Action | Status | |---|---|---|---| @@ -332,6 +335,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12. | 2026-10-19 | minor | Ctrl+Enter (`range.fill`) gives each cell what typing the input there gives: a General cell gets the automatic number format (`5%`, `$5`, `3/4/2026`, `=TODAY()`) even when it already held a value, and a cell with its own format, a formatted row or column, or Text keeps it. Cells that held a value used to keep General (`5%` showed 0.05), and empty cells took the active cell's format | | 2026-10-19 | trivial | While a mouse button is held (a click or a drag selecting cells) the selection outline is drawn on its cells at once instead of gliding after the pointer, which read as lag; keyboard moves still glide | | 2026-10-18 | minor | Keytip letters typed with left Alt held continue the sequence (Alt+H, O, A / Alt+H, O, I ran nothing before: Alt+letter cancelled keytips); other Alt combinations, AltGr and macOS Option are unchanged (#1846) | +| 2026-10-14 | minor | Punctuation shortcuts follow the character the keyboard layout types, digits keep their position: on a Croatian or German keyboard Ctrl+Shift+, (`;`) inserts the date instead of decreasing the font size, Ctrl+Shift+. (`:`) the time, Ctrl++ opens Insert, Ctrl+' copies the formula above, and Ctrl+Shift+0 (`=`) unhides columns instead of opening Insert | | 2026-10-17 | minor | A Ctrl+Alt+letter key that types a character (a user-defined Windows hotkey such as Ctrl+Alt+A for `ä`) types it instead of running the Ctrl+letter shortcut, e.g. Select All (#1530) | | 2026-10-16 | minor | Right-drag on the fill handle opens the fill menu on release: Copy Cells, Fill Series, Fill Formatting Only, Fill Without Formatting, Series…; Esc cancels the drag or closes the menu without filling | | 2026-10-16 | minor | With the active cell in a Table whose header row is scrolled out of view, the column headings show the header names and their filter buttons in place of the letters (#1423) |