Merge pull request #282 from vangel76/fix/name-box-enter

UI: Name Box Enter goes to the typed cell, not the one below (#247)
This commit is contained in:
Brandon Thomas
2026-10-11 11:24:39 -04:00
2 changed files with 24 additions and 0 deletions
+4
View File
@@ -112,6 +112,10 @@ fn name_box(app: &mut SheetApp, ui: &mut egui::Ui, t: &Tokens) {
}
if resp.lost_focus() {
if ui.input(|i| i.key_pressed(Key::Enter)) {
// The Enter that commits the Name Box is used up here. Left in the frame's input, the
// grid (drawn after the formula bar, and focused again now the box let go) would read
// it as its own Enter and move the active cell one row down from the jump target (#247).
ui.input_mut(|i| i.events.retain(|e| !matches!(e, egui::Event::Key { key: Key::Enter, .. })));
let target = text.trim().to_string();
if !target.is_empty() && target != shown {
// A new name for the selection, or a place to go.
+20
View File
@@ -125,6 +125,26 @@ fn space_toggles_the_active_checkbox_without_clicking_the_hovered_cell() {
assert!(h.state().editor.is_none());
}
#[test]
fn name_box_enter_goes_to_the_typed_cell_not_the_one_below() {
// #247: typing A1 in the Name Box and pressing Enter selected A2; the grid replayed the Enter.
let mut h = harness(blank());
h.state_mut().session.run("selection.set", json!({"cell": "C5"})).unwrap();
h.run_steps(2);
h.ctx.memory_mut(|m| m.request_focus(egui::Id::new("gridcraft.name_box")));
h.run_steps(2);
h.input_mut().events.push(Event::Key { key: Key::A, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::COMMAND });
h.input_mut().events.push(Event::Text("A1".into()));
h.run_steps(2);
key(&mut h, Key::Enter, Modifiers::NONE);
h.run_steps(2);
assert_eq!(h.state().session.active().unwrap().selection.active, CellRef::new(0, 0));
assert!(h.state().name_box.is_none());
// The grid has the focus back: a plain Enter there still moves down.
key(&mut h, Key::Enter, Modifiers::NONE);
assert_eq!(h.state().session.active().unwrap().selection.active, CellRef::new(1, 0));
}
#[test]
fn typing_enters_values_and_moves_down() {
let mut h = harness(blank());