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.
This commit is contained in:
prxnvt committed 2026-11-02 03:06:40 -05:00
1 parent 8495cc99e1
commit d1f69878f6
3 files changed
+36 -6

No files matched your search

+12 -5
View File
@@ -165,13 +165,20 @@ fn grid_events(app: &mut SheetApp, ctx: &egui::Context, sh: &Sheet) -> Vec<egui:
}
/// Whether the focused form control takes `ev`: arrows, Page Up and Down, Home, End, Space and
/// Enter without Ctrl, Cmd or Alt, and, for a button, the space a Space press types (Space
/// presses the button and doesn't start typing in a cell; a slider or spin button doesn't take
/// Space, so its space starts a cell edit like any other character). A key press the control
/// doesn't take goes to the grid, and a focused button gives the keyboard back with it.
/// Enter without Ctrl, Cmd or Alt, and the space a Space press types when it must not start a
/// cell edit: for a button, which Space presses, and on a checkbox cell, which the Space key
/// toggles (a slider or spin button doesn't take Space, so Space on a cell does what it does with
/// no control focused: it toggles a checkbox cell, or its space starts a cell edit like any other
/// character). A key press the control doesn't take goes to the grid, and a focused button gives
/// the keyboard back with it.
fn form_control_event(app: &mut SheetApp, sh: &Sheet, ev: &egui::Event) -> 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;
+23
View File
@@ -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]
+1 -1
View File
@@ -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) |