mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-26 13:22:34 +00:00
UI: Excel for Mac Control+Q opens Quick Analysis; Command+Q stays Quit
ribbon::shortcut is only reached with the command modifier, so on a Mac Control+Q did nothing and Command+Q toggled Quick Analysis next to the native Quit item. The keymap now maps Mac Control+Q (without Command, Option or Shift) to Shortcut::QuickAnalysis, which shares the ribbon handler and its single-cell alert suppression, and the ribbon Q branch ignores Command on a Mac. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7984f0f2bd
commit
d098a7dfc3
@@ -41,6 +41,8 @@ pub enum Shortcut {
|
||||
Zoom(i32),
|
||||
/// Ctrl+Alt+Shift+P: edit the active cell as Python code (Python mode).
|
||||
PythonMode,
|
||||
/// Excel for Mac Control+Q: Quick Analysis (Windows Ctrl+Q is in `ribbon::shortcut`).
|
||||
QuickAnalysis,
|
||||
}
|
||||
|
||||
fn run(id: &'static str) -> Shortcut {
|
||||
@@ -139,6 +141,8 @@ fn lookup_control_shortcuts(ctx: LookupContext) -> Option<Shortcut> {
|
||||
// Windows Ctrl+; is in `ribbon::shortcut`; Excel for Mac uses Control+; and Command+;.
|
||||
Semicolon if mac && ctrl => Shortcut::Date,
|
||||
Semicolon if mac && cmd && !s => Shortcut::Time,
|
||||
// Control+Q only: Command+Q is the native Quit item.
|
||||
Q if mac && ctrl && !m.command && !s => Shortcut::QuickAnalysis,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -349,6 +353,7 @@ pub(crate) fn dispatch(app: &mut SheetApp, ctx: &egui::Context, key: Key, physic
|
||||
}
|
||||
Shortcut::Edit => app.begin_edit(None, false),
|
||||
Shortcut::PythonMode => app.toggle_python_mode(),
|
||||
Shortcut::QuickAnalysis => crate::ribbon::quick_analysis(app),
|
||||
Shortcut::ContextMenu => app.grid.context_menu = Some(geo.cell_rect(sh, active).center()),
|
||||
Shortcut::DropDown => {
|
||||
if sh.validations.iter().any(|d| d.in_cell_dropdown && d.ranges.iter().any(|r| r.contains(active))) {
|
||||
|
||||
@@ -37,6 +37,7 @@ use home::home;
|
||||
use insert::{draw, insert};
|
||||
use page_layout::page_layout;
|
||||
use review::review;
|
||||
pub(crate) use shortcuts::quick_analysis;
|
||||
pub use shortcuts::shortcut;
|
||||
pub use title_bar::{MAC_CONTENT_LEFT, MAC_TITLE_BAR, TITLE_LEFT_PAD, title_bar};
|
||||
use title_bar::{TITLE_BAR_H, TITLE_CONTROL_H};
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
use super::{Key, Modifiers, SheetApp, json};
|
||||
|
||||
/// Ctrl+Q (Control+Q in Excel for Mac): Quick Analysis. A single cell has nothing to analyse,
|
||||
/// which is not worth an alert, but several areas deserve to be told why nothing opened.
|
||||
pub(crate) fn quick_analysis(app: &mut SheetApp) {
|
||||
if let Err(e) = crate::quick_analysis::toggle(app, None)
|
||||
&& app.session.active().is_some_and(|d| d.selection.ranges.len() > 1)
|
||||
{
|
||||
app.alert(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// Command-key shortcuts when the grid has focus.
|
||||
pub fn shortcut(app: &mut SheetApp, key: Key, m: Modifiers) {
|
||||
let shift = m.shift;
|
||||
@@ -43,14 +53,9 @@ pub fn shortcut(app: &mut SheetApp, key: Key, m: Modifiers) {
|
||||
Key::T => Some(("insert.table", json!({}))),
|
||||
Key::E => Some(("edit.flashFill", json!({}))),
|
||||
// Plain Ctrl+Q only: Ctrl+Shift+Q and Ctrl+Alt+Q (AltGr+Q) are not Quick Analysis.
|
||||
Key::Q if !shift && !m.alt => {
|
||||
// Quick Analysis; a single cell has nothing to analyse, which is not worth an alert,
|
||||
// but several areas deserve to be told why nothing opened.
|
||||
if let Err(e) = crate::quick_analysis::toggle(app, None)
|
||||
&& app.session.active().is_some_and(|d| d.selection.ranges.len() > 1)
|
||||
{
|
||||
app.alert(e);
|
||||
}
|
||||
// Command+Q on a Mac is the native Quit item; Control+Q there goes through the keymap.
|
||||
Key::Q if !shift && !m.alt && !m.mac_cmd => {
|
||||
quick_analysis(app);
|
||||
None
|
||||
}
|
||||
Key::Num1 => {
|
||||
|
||||
@@ -315,3 +315,28 @@ fn only_plain_ctrl_q_toggles_quick_analysis() {
|
||||
key(&mut h, Key::Q, CTRL);
|
||||
assert!(h.state().grid.quick_analysis.open.is_some(), "Ctrl+Q");
|
||||
}
|
||||
|
||||
/// Excel for Mac: Control+Q (ctrl without command) opens Quick Analysis, Command+Q is left to the
|
||||
/// native Quit item, and a single cell still opens nothing without an alert.
|
||||
#[test]
|
||||
fn mac_control_q_toggles_quick_analysis_and_command_q_does_not() {
|
||||
const MAC_CONTROL: Modifiers = Modifiers { alt: false, ctrl: true, shift: false, mac_cmd: false, command: false };
|
||||
const MAC_COMMAND: Modifiers = Modifiers { alt: false, ctrl: false, shift: false, mac_cmd: true, command: true };
|
||||
assert_eq!(lookup(Key::Q, Some(Key::Q), MAC_CONTROL, true), Some(Shortcut::QuickAnalysis));
|
||||
assert_eq!(lookup(Key::Q, Some(Key::Q), MAC_COMMAND, true), None);
|
||||
assert_eq!(lookup(Key::Q, Some(Key::Q), MAC_CONTROL, false), None, "Windows Ctrl+Q goes through ribbon::shortcut");
|
||||
let mac = |sel: &str| crate::common::os_harness(book(sel), egui::os::OperatingSystem::Mac);
|
||||
let mut h = mac("A1:B3");
|
||||
key(&mut h, Key::Q, MAC_COMMAND);
|
||||
assert!(h.state().grid.quick_analysis.open.is_none(), "Command+Q is Quit");
|
||||
key(&mut h, Key::Q, Modifiers { shift: true, ..MAC_CONTROL });
|
||||
assert!(h.state().grid.quick_analysis.open.is_none(), "Control+Shift+Q");
|
||||
key(&mut h, Key::Q, MAC_CONTROL);
|
||||
assert!(h.state().grid.quick_analysis.open.is_some(), "Control+Q opens");
|
||||
key(&mut h, Key::Q, MAC_CONTROL);
|
||||
assert!(h.state().grid.quick_analysis.open.is_none(), "Control+Q again closes");
|
||||
let mut h = mac("B2");
|
||||
key(&mut h, Key::Q, MAC_CONTROL);
|
||||
assert!(h.state().grid.quick_analysis.open.is_none());
|
||||
assert!(h.state().message.is_none() && h.state().toast.is_none(), "no alert for a single cell");
|
||||
}
|
||||
|
||||
+2
-2
@@ -145,10 +145,10 @@ otherwise. Number-format and border keys match the physical key (Ctrl+Shift+4, w
|
||||
| Ctrl+Alt+Shift+P | Cmd+Option+Shift+P | Python mode on or off | **added** |
|
||||
| F3 | not checked | Paste Name dialog, only when the workbook has names: OK puts the name at the caret of the formula being edited (or starts `=Name`), Paste List writes each name and what it refers to from the active cell (`formulas.pasteName`) | **added** |
|
||||
| F1, F4 (repeat), F6 / Shift+F6, F8 / Shift+F8, F11, End mode | same | help, Repeat, pane cycling, extend/add mode, chart sheet | missing (no such feature yet) |
|
||||
| Ctrl+Q | Ctrl+Q | Quick Analysis | **added** (#791) |
|
||||
| Ctrl+Q | Control+Q (Cmd+Q stays Quit) | Quick Analysis | **added** (#791) |
|
||||
| Ctrl+A after a function name, Ctrl+Shift+U, Ctrl+Alt+P | same | Function Arguments, formula bar height, tooltips | missing |
|
||||
| F1, F3, F4 (repeat), F6 / Shift+F6, F8 / Shift+F8, F11, End mode | same | help, Paste Name, Repeat, pane cycling, extend/add mode, chart sheet | missing (no such feature yet) |
|
||||
| Ctrl+Q | Ctrl+Q | Quick Analysis | **added** (#791) |
|
||||
| Ctrl+Q | Control+Q (Cmd+Q stays Quit) | Quick Analysis | **added** (#791) |
|
||||
| Ctrl+A after a function name, Ctrl+Alt+P | same | Function Arguments, tooltips | missing |
|
||||
| Ctrl+Shift+A after a function name | Control+Shift+A | argument names: `=SUMIF(` becomes `=SUMIF(range,criteria,sum_range)`, the `(` added when missing; one Undo takes them back | **added** |
|
||||
| Ctrl+Shift+U | Control+Shift+U | expand or collapse the formula bar (`view.expandFormulaBar`), on the grid and while editing; on Windows and Linux it no longer underlines | **added** |
|
||||
|
||||
Reference in New Issue
Block a user