From 443301f9eea66b69b1328b1faa831008ea6b7799 Mon Sep 17 00:00:00 2001 From: Marco Arnulfo Date: Tue, 13 Oct 2026 00:21:25 +0200 Subject: [PATCH] UI: Enter pastes the copied range and ends copy mode (fixes #845) --- crates/ui-egui/src/grid.rs | 6 ++++++ crates/ui-egui/tests/clipboard.rs | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index d0eef85..7673deb 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -2398,6 +2398,12 @@ fn keyboard(app: &mut SheetApp, ctx: &egui::Context, resp: &egui::Response, geo: let _ = app.session.run("selection.set", json!({"cell": CellRef::new(a.row, 0).a1()})); app.grid.ensure_visible = true; } + // Excel: Enter while a copied range is marked pastes it and ends copy mode. + Key::Enter if !m.alt && !m.ctrl && !shift && !cmd && app.session.clipboard.is_some() => { + app.run_or_alert("edit.paste", json!({})); + app.session.clipboard = None; + app.grid.ensure_visible = true; + } Key::Enter => { if m.alt || m.ctrl { app.begin_edit(None, false); diff --git a/crates/ui-egui/tests/clipboard.rs b/crates/ui-egui/tests/clipboard.rs index 71fe336..e2ac4fb 100644 --- a/crates/ui-egui/tests/clipboard.rs +++ b/crates/ui-egui/tests/clipboard.rs @@ -116,3 +116,24 @@ fn copying_multiple_areas_copies_lined_up_areas_and_explains_the_rest() { assert_eq!(h.state().message.as_ref().map(|(_, text)| text.as_str()), Some("This action won't work on multiple selections.")); assert_eq!(h.state().session.clipboard.as_ref().map(|c| c.areas.len()), Some(2), "the earlier copy stays"); } + +#[test] +fn enter_pastes_the_copied_cells_and_ends_copy_mode() { + // #845: with the marching ants showing, Enter pastes into the selection and cancels the copy. + let mut h = harness(Services::default()); + h.input_mut().events.push(Event::Copy); + h.step(); + h.state_mut().run("selection.set", json!({"cell": "D5"})).unwrap(); + h.key_press(egui::Key::Enter); + h.run_steps(2); + let value = |r, c| h.state().session.active().and_then(|d| d.wb.active().map(|s| s.value(gridcraft_engine::core::CellRef::new(r, c)))); + assert_eq!(value(4, 3), Some(gridcraft_engine::core::Value::text("Name"))); + assert_eq!(value(5, 4), Some(gridcraft_engine::core::Value::number(42.0))); + assert!(h.state().session.clipboard.is_none(), "the marching ants are gone"); + assert_eq!(h.state().session.active().map(|d| d.selection.active.a1()), Some("D5".to_string()), "Enter does not also move down"); + + // Copy mode is over: the next Enter just moves. + h.key_press(egui::Key::Enter); + h.run_steps(2); + assert_eq!(h.state().session.active().map(|d| d.selection.active.a1()), Some("D6".to_string())); +}