From d1f69878f6701490a2ba2b05d89b789b57be0dba Mon Sep 17 00:00:00 2001 From: prxnvt <53838599+prxnvt@users.noreply.github.com> Date: Mon, 2 Nov 2026 03:06:40 -0500 Subject: [PATCH] Form controls: Space on a checkbox cell toggles it once while a slider or spin button is focused With a slider or spin button focused, the Space key reached the grid and toggled a checkbox cell, and the space it types then started a cell edit over the toggle (Escape cancelled the edit but not the toggle). Now the typed space is dropped while a control is focused and the active cell is a checkbox, as it is for a focused button: Space on a cell does what it does with no control focused and nothing more, a checkbox cell toggles once with no edit, any other cell starts an edit with a space. The path with no control focused is unchanged. Test (kittest): space_on_a_checkbox_cell_toggles_it_once_while_a_slider_is_focused (toggled once, no editor, the slider's value and focus unchanged; a second Space toggles back). docs/ui-parity.md says so. --- crates/ui-egui/src/grid/keyboard.rs | 17 ++++++++++++----- crates/ui-egui/tests/it/form_controls.rs | 23 +++++++++++++++++++++++ docs/ui-parity.md | 2 +- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/grid/keyboard.rs b/crates/ui-egui/src/grid/keyboard.rs index 8f3dfb141..4c0ca282d 100644 --- a/crates/ui-egui/src/grid/keyboard.rs +++ b/crates/ui-egui/src/grid/keyboard.rs @@ -165,13 +165,20 @@ fn grid_events(app: &mut SheetApp, ctx: &egui::Context, sh: &Sheet) -> Vec bool { match ev { - egui::Event::Text(text) => text == " " && app.selected_object.is_none() && crate::form_controls::focused_button(app, sh), + egui::Event::Text(text) => { + text == " " + && app.selected_object.is_none() + && app.grid.focused_control.is_some() + && (crate::form_controls::focused_button(app, sh) || is_checkbox(sh, app)) + } egui::Event::Key { key, pressed: true, repeat, modifiers: m, .. } => { if !m.command && !m.ctrl && !m.alt && crate::form_controls::key(app, sh, *key, *repeat) { return true; diff --git a/crates/ui-egui/tests/it/form_controls.rs b/crates/ui-egui/tests/it/form_controls.rs index f202df1be..44d1f9f32 100644 --- a/crates/ui-egui/tests/it/form_controls.rs +++ b/crates/ui-egui/tests/it/form_controls.rs @@ -347,6 +347,29 @@ fn space_starts_a_cell_edit_while_a_slider_or_spin_button_is_focused() { } } +/// With a slider or spin button focused, Space on a cell does what it does with no control +/// focused and nothing more: a checkbox cell toggles once and no edit starts (the typed space is +/// dropped, as the toggle is what Space does there), and the control's value is unchanged. +#[test] +fn space_on_a_checkbox_cell_toggles_it_once_while_a_slider_is_focused() { + let (mut h, ids) = fixture(); + h.state_mut().run("insert.checkbox", json!({"range": "A20"})).unwrap(); + h.run_steps(2); + assert_eq!(cell(&h, "A20"), Value::Bool(false)); + let at = thumb(&h, ids.slider).center(); + click(&mut h, at); + assert_eq!(h.state().grid.focused_control, Some(ids.slider)); + let value = control(&h, ids.slider).value; + space(&mut h); + assert_eq!(cell(&h, "A20"), Value::Bool(true), "Space toggled the box once"); + assert!(h.state().editor.is_none(), "and started no edit"); + assert_eq!(control(&h, ids.slider).value, value, "the slider is unchanged"); + assert_eq!(h.state().grid.focused_control, Some(ids.slider), "and keeps the keyboard"); + space(&mut h); + assert_eq!(cell(&h, "A20"), Value::Bool(false), "a second Space toggles it back"); + assert!(h.state().editor.is_none()); +} + /// A right-click on a cell takes the keyboard from a button, like any other click on the grid: /// the Enter that follows does not press it again. #[test] diff --git a/docs/ui-parity.md b/docs/ui-parity.md index f0ead2518..7147bd400 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -69,7 +69,7 @@ this logic, with one undo step. | Copy as HTML table for other apps | done (#36, 10-10) | | Context menu on cells | 16 items (Cut, Copy, Paste, Paste Special, Insert, Delete, Clear Contents, Filter by value, Sort, New Comment, New Note, Format Cells, Pick From Drop-down List, Define Name, Link). Insert Copied Cells (Insert Cut Cells for whole rows/columns) while the clipboard holds a copy (#21). Show Details on a PivotTable's value, subtotal or grand total cell (`pivot.showDetails`). Missing: Insert Cut Cells for a cell block, paste-option icons, Quick Analysis, Get Data from Table, Show Changes, Smart Lookup | | Move and resize charts, pictures and shapes | done (#190, #213): charts, pictures, shapes and slicers select with a frame of eight handles; each handle resizes only its own edges (they never cross), the body moves the object, and the pointer shows a resize or move cursor; Delete or Backspace deletes the selected object and Escape drops the selection; double-click edits a text box, opens Format Chart for a chart. Rotation handle, Shift for proportional resizing, Alt to snap to cells and multi-object selection missing | -| Form controls: buttons, scroll bars (sliders), spin buttons | done (10-31): Insert › Controls (Button, Slider, Spin Button; Excel has them under Developer › Insert) places one by a drag, or at its default size by a click; a click works a control: drag the thumb, page on the track, click or hold an arrow (a drag or a hold is one undo step), press a button, which runs a macro or a command and asks first in a workbook opened from a file; the control last worked takes the arrows, Page Up and Page Down, Home, End, and Space or Enter (a button gives the keyboard back as soon as the grid takes a key or a right-click; Space on a slider or spin button starts a cell edit like any other character); Ctrl or Cmd+click or a right-click selects it to move or resize; its menu has Edit Text, Assign Action, Format Control and Delete. Check boxes, option buttons, list boxes and drop-downs (form controls) are kept from files but not shown | +| Form controls: buttons, scroll bars (sliders), spin buttons | done (10-31): Insert › Controls (Button, Slider, Spin Button; Excel has them under Developer › Insert) places one by a drag, or at its default size by a click; a click works a control: drag the thumb, page on the track, click or hold an arrow (a drag or a hold is one undo step), press a button, which runs a macro or a command and asks first in a workbook opened from a file; the control last worked takes the arrows, Page Up and Page Down, Home, End, and Space or Enter (a button gives the keyboard back as soon as the grid takes a key or a right-click; Space on a slider or spin button does what it does with no control focused: it toggles a checkbox cell or starts a cell edit like any other character); Ctrl or Cmd+click or a right-click selects it to move or resize; its menu has Edit Text, Assign Action, Format Control and Delete. Check boxes, option buttons, list boxes and drop-downs (form controls) are kept from files but not shown | | Context menus on row/column headers, sheet tabs, charts, shapes | headers and tabs done; objects partial | | Quick Analysis (Ctrl+Q) | missing | | Smooth scrolling, scrollbars | done; vertical scrollbar added 10-09 (#73); horizontal scrollbar in the tab bar (60/40 split, drag, track click pages) 10-13 (#176, #840); dragging the handle at the scrollbar's left edge gives the tabs more or less of the bar; each workbook keeps its share while it is open (not saved in the file) |