From fdad356fd25aa95166c5150a6e6aca5cb877f13a Mon Sep 17 00:00:00 2001 From: kezmdor <15539254+kezmdor@users.noreply.github.com> Date: Tue, 20 Oct 2026 08:39:07 +0200 Subject: [PATCH 1/5] AutoSum on one cell proposes its range in the editor, like Excel (fixes #1834) AutoSum from the ribbon or keyboard entered `=SUM(range)` at once, so the range could only be changed by editing the formula afterwards. On one cell it now runs with `enter: false` and leaves `=SUM(B2:B4)` in the editor with `B2:B4` pointed and selected: a click, drag, arrow key or typing replaces it, and Enter enters the formula. With nothing to sum the caret waits between the parentheses of `=SUM()`. A block still gets its totals at once, and programmatic `formulas.autoSum` (control channel, CLI, MCP) is unchanged. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/editor.rs | 43 ++++++ crates/ui-egui/src/formula_bar.rs | 6 +- crates/ui-egui/src/lib.rs | 22 +++ crates/ui-egui/tests/autosum_edit.rs | 149 +++++++++++++++++++++ crates/ui-egui/tests/keyboard_shortcuts.rs | 7 +- docs/ui-parity.md | 5 +- 6 files changed, 226 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/tests/autosum_edit.rs diff --git a/crates/ui-egui/src/editor.rs b/crates/ui-egui/src/editor.rs index 799109f890..64fa3627d5 100644 --- a/crates/ui-egui/src/editor.rs +++ b/crates/ui-egui/src/editor.rs @@ -41,6 +41,8 @@ pub struct EditState { pub completion: Option, /// Move the caret to the end on the next frame. pub caret_to_end: bool, + /// Select from this char index to `caret` when the caret is next pushed into the widget. + pub select_from: Option, } impl EditState { @@ -62,6 +64,7 @@ impl EditState { sync_caret: true, caret_to_end: true, completion: None, + select_from: None, } } @@ -107,6 +110,23 @@ impl EditState { self.sync_caret = true; } + /// Points and selects the argument of the call that ends the text, as AutoSum proposes it + /// (`=SUM(B1:B3)`): a click, drag, arrow key or typing replaces `B1:B3`. An arrow key moves + /// from the range's first cell, as in Excel: ↑ on `=SUM(A2:A4)` gives `=SUM(A1)`. With no + /// argument (`=SUM()`) the caret goes between the parentheses. + pub fn point_last_argument(&mut self) { + let Some(open) = self.text.rfind('(') else { return }; + let Some(close) = self.text.len().checked_sub(1).filter(|&c| c > open && self.text.ends_with(')')) else { return }; + let chars = |byte: usize| self.text.get(..byte).map_or(0, |t| t.chars().count()); + let (start, end) = (open + 1, close); + self.caret = chars(end); + self.point = (start < end).then_some((start, end)); + self.select_from = (start < end).then(|| chars(start)); + self.point_cell = self.text.get(start..end).and_then(RangeRef::parse).map(|r| r.start); + self.caret_to_end = false; + self.sync_caret = true; + } + /// Updates function autocomplete for the word before the caret. pub fn update_autocomplete(&mut self, names: &[String]) { self.autocomplete.clear(); @@ -316,6 +336,29 @@ mod tests { assert!(!e2.can_point()); } + #[test] + fn autosum_points_and_selects_its_proposed_range() { + // #1834: Excel leaves AutoSum's range ready to be replaced by pointing or typing. + let mut e = EditState::new(0, CellRef::new(3, 0), "=SUM(A1:A3)".into(), true, false); + e.point_last_argument(); + assert!(e.can_point()); + assert_eq!((e.caret, e.select_from, e.point), (10, Some(5), Some((5, 10)))); + assert_eq!(e.point_cell, Some(CellRef::new(0, 0)), "arrow keys move from the range's first cell"); + e.insert_ref("A2"); + assert_eq!(e.text, "=SUM(A2)"); + // No proposal: the caret waits between the parentheses. + let mut e = EditState::new(0, CellRef::new(3, 0), "=SUMA()".into(), true, false); + e.point_last_argument(); + assert!(e.can_point()); + assert_eq!((e.caret, e.select_from, e.point), (6, None, None)); + e.insert_ref("B2"); + assert_eq!(e.text, "=SUMA(B2)"); + // Text without a closing call is left alone. + let mut e = EditState::new(0, CellRef::new(3, 0), "=SUM(".into(), true, false); + e.point_last_argument(); + assert_eq!((e.caret, e.point), (5, None)); + } + #[test] fn autocomplete_and_hints() { let names: Vec = ["SUM", "SUMIF", "SUMPRODUCT", "AVERAGE"].iter().map(|s| s.to_string()).collect(); diff --git a/crates/ui-egui/src/formula_bar.rs b/crates/ui-egui/src/formula_bar.rs index 7f1ad87fc1..012a570d01 100644 --- a/crates/ui-egui/src/formula_bar.rs +++ b/crates/ui-egui/src/formula_bar.rs @@ -298,7 +298,11 @@ pub fn editor_widget(app: &mut SheetApp, ui: &mut egui::Ui, id: egui::Id, font: ed.request_focus = false; ed.sync_caret = false; let cursor = egui::text::CCursor::new(ed.caret); - output.state.cursor.set_char_range(Some(egui::text::CCursorRange::one(cursor))); + let range = match ed.select_from.take() { + Some(from) => egui::text::CCursorRange::two(egui::text::CCursor::new(from), cursor), + None => egui::text::CCursorRange::one(cursor), + }; + output.state.cursor.set_char_range(Some(range)); output.state.store(ui.ctx(), id); } else if resp.clicked() || resp.gained_focus() { // Clicking into the other editor moves editing there. diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index f549aec2b5..4704ef20d2 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -528,11 +528,33 @@ impl SheetApp { if id == "file.exportPdf" && self.services.pick_save.is_some() && params.get("path").and_then(Json::as_str).is_none_or(str::is_empty) { return self.export_pdf_with_picker(params); } + // Menu-style AutoSum on one cell proposes its formula in the editor with the range + // pointed and selected, so a click, drag, arrow key or typing replaces it, as in Excel. + // Programmatic callers use `run` and get the total entered. + if id == "formulas.autoSum" && params.get("range").is_none() && self.session.active().is_some_and(|d| d.selection.current().is_single()) { + return self.auto_sum_in_editor(params); + } if let Err(e) = self.run(id, params) { self.alert(e); } } + fn auto_sum_in_editor(&mut self, params: Json) { + let mut params = if params.is_object() { params } else { json!({}) }; + if let Some(map) = params.as_object_mut() { + map.insert("enter".into(), Json::Bool(false)); + } + if let Err(e) = self.run("formulas.autoSum", params) { + return self.alert(e); + } + if let Some(ed) = self.editor.as_mut() { + ed.point_last_argument(); + if ed.can_point() { + self.session.mode = gridcraft_engine::Mode::Point; + } + } + } + /// Asks for a `.pdf` path with the save picker, then re-runs `file.exportPdf` with it. Other /// params (range, sheets, fitToPage) are kept. A cancelled picker does nothing. fn export_pdf_with_picker(&mut self, mut params: Json) { diff --git a/crates/ui-egui/tests/autosum_edit.rs b/crates/ui-egui/tests/autosum_edit.rs new file mode 100644 index 0000000000..eae1da4079 --- /dev/null +++ b/crates/ui-egui/tests/autosum_edit.rs @@ -0,0 +1,149 @@ +//! AutoSum from the ribbon or keyboard on one cell proposes its formula in the editor, with the +//! range ready to be replaced by pointing or typing, as in Excel (#1834). + +use egui::{Event, Key, Modifiers, PointerButton, Pos2}; +use gridcraft_engine::core::{CellRef, Value}; +use gridcraft_engine::{Mode, Session}; +use gridcraft_ui_egui::{SheetApp, grid::Geo}; +use serde_json::json; + +type Harness = egui_kittest::Harness<'static, SheetApp>; + +/// 1, 2, 3 in A1:A3 and `selected` selected. +fn harness(selected: &str) -> Harness { + harness_at("A1", selected) +} + +/// 1, 2, 3 down from `first` and `selected` selected. +fn harness_at(first: &str, selected: &str) -> Harness { + let mut session = Session::new(); + session.new_workbook(); + session.execute("range.setValues", json!({"range": first, "values": [[1], [2], [3]]})).unwrap(); + session.execute("selection.set", json!({"range": selected})).unwrap(); + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state( + |ui, app: &mut SheetApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + SheetApp::new(session, Default::default()), + ); + h.run_steps(4); + h +} + +/// The AutoSum button: a menu-style run. +fn auto_sum(h: &mut Harness) { + h.state_mut().run_or_alert("formulas.autoSum", json!({})); + h.run_steps(2); +} + +fn editing(h: &Harness) -> Option { + h.state().editor.as_ref().map(|e| e.text.clone()) +} + +fn input(h: &Harness, cell: &str) -> String { + h.state().session.active().unwrap().wb.active().unwrap().input_text(CellRef::parse(cell).unwrap()) +} + +fn cell_center(h: &Harness, cell: &str) -> Pos2 { + let app = h.state(); + let sheet = app.session.active().unwrap().wb.active().unwrap(); + let geo = Geo::new(sheet, app.grid.rect.unwrap(), app.view().scroll); + geo.cell_rect(sheet, CellRef::parse(cell).unwrap()).center() +} + +fn pointer(h: &mut Harness, cell: &str, pressed: bool) { + let pos = cell_center(h, cell); + h.input_mut() + .events + .extend([Event::PointerMoved(pos), Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }]); + h.run_steps(2); +} + +fn enter(h: &mut Harness) { + for pressed in [true, false] { + h.input_mut().events.push(Event::Key { key: Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }); + } + h.run_steps(2); +} + +#[test] +fn autosum_on_one_cell_proposes_its_range_in_the_editor() { + let mut h = harness("A4"); + auto_sum(&mut h); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A1:A3)")); + assert_eq!(h.state().session.mode, Mode::Point); + assert_eq!(input(&h, "A4"), "", "nothing is entered before Enter"); + enter(&mut h); + assert_eq!(input(&h, "A4"), "=SUM(A1:A3)"); + assert_eq!(h.state().session.active().unwrap().wb.active().unwrap().value(CellRef::parse("A4").unwrap()), Value::Number(6.0)); +} + +#[test] +fn a_click_or_drag_replaces_the_proposed_range() { + let mut h = harness("A4"); + auto_sum(&mut h); + pointer(&mut h, "A2", true); + pointer(&mut h, "A2", false); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A2)")); + + let mut h = harness("A4"); + auto_sum(&mut h); + pointer(&mut h, "A1", true); + let to = cell_center(&h, "A2"); + for pos in [to, to + egui::vec2(1.0, 0.0)] { + h.input_mut().events.push(Event::PointerMoved(pos)); + h.step(); + } + pointer(&mut h, "A2", false); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A1:A2)")); + enter(&mut h); + assert_eq!(input(&h, "A4"), "=SUM(A1:A2)"); +} + +#[test] +fn an_arrow_key_points_from_the_proposed_range() { + // Observed in Excel for the web: ↑ after AutoSum moves from the range's first cell. + let mut h = harness_at("A2", "A5"); + auto_sum(&mut h); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A2:A4)")); + for pressed in [true, false] { + h.input_mut().events.push(Event::Key { key: Key::ArrowUp, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }); + } + h.run_steps(2); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A1)")); +} + +#[test] +fn typing_replaces_the_proposed_range() { + let mut h = harness("A4"); + auto_sum(&mut h); + h.input_mut().events.push(Event::Text("A2:A3".into())); + h.run_steps(2); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A2:A3)")); +} + +#[test] +fn with_nothing_to_sum_the_caret_waits_between_the_parentheses() { + let mut h = harness("C10"); + auto_sum(&mut h); + assert_eq!(editing(&h).as_deref(), Some("=SUM()")); + pointer(&mut h, "A1", true); + pointer(&mut h, "A1", false); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A1)")); +} + +#[test] +fn a_block_and_programmatic_calls_enter_the_totals_at_once() { + let mut h = harness("A1:A4"); + auto_sum(&mut h); + assert!(h.state().editor.is_none()); + assert_eq!(input(&h, "A4"), "=SUM(A1:A3)"); + + // The control channel, CLI and MCP run commands with `run`: no editor. + let mut h = harness("A4"); + h.state_mut().run("formulas.autoSum", json!({})).unwrap(); + h.run_steps(2); + assert!(h.state().editor.is_none()); + assert_eq!(input(&h, "A4"), "=SUM(A1:A3)"); +} diff --git a/crates/ui-egui/tests/keyboard_shortcuts.rs b/crates/ui-egui/tests/keyboard_shortcuts.rs index 78bc966f51..5fc62f1e0f 100644 --- a/crates/ui-egui/tests/keyboard_shortcuts.rs +++ b/crates/ui-egui/tests/keyboard_shortcuts.rs @@ -235,9 +235,10 @@ fn alt_equals_autosum_does_not_also_type_the_equals_sign() { for (selected, cell, formula) in [("A4", "A4", "=SUM(A1:A3)"), ("C3", "C3", "=SUM(A3:B3)"), ("A1:B3", "B4", "=SUM(B1:B3)")] { let mut h = harness(book(selected)); alt_equals(&mut h); - assert_eq!(input(&h, cell), formula, "Alt+= on {selected}"); - assert!(h.state().editor.is_none(), "Alt+= on {selected} started an edit"); - // Enter moves on: there is no stray `=` edit to commit. + // One cell: the formula waits in the editor for Enter, as in Excel (#1834); a block gets + // its totals at once. Either way without a stray `=`. + let editing = h.state().editor.as_ref().map(|e| e.text.clone()); + assert_eq!(editing.as_deref(), (!selected.contains(':')).then_some(formula), "Alt+= on {selected}"); key(&mut h, Key::Enter, Modifiers::NONE); assert!(h.state().message.is_none(), "Alt+= on {selected}: {:?}", h.state().message); assert_eq!(input(&h, cell), formula); diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 34cb502f54..2de457262c 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-19 · **Change:** minor (Ctrl+Enter fill gives each cell the automatic number format typing gives it; keytip letters typed with Alt held, #1846) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-20 · **Change:** minor (AutoSum on one cell proposes its range in the editor, #1834) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Interaction, controls and feel, against Excel. Part of [target-app-parity.md](target-app-parity.md). **UI/UX fidelity: ~55% ready, 50–80 h** (estimated). Ribbon command coverage is measured @@ -48,7 +48,7 @@ this logic, with one undo step. | Fill handle: drag to fill series, double-click to fill down, right-drag menu | fill done (Ctrl+drag swaps copy and series); right-drag menu missing | | Drag-move and drag-copy cells (border drag, Ctrl/Option, Shift to insert) | done (M3) | | In-cell editing, Enter/Tab movement, Alt/Option+Enter line breaks | done | -| Point mode (click/drag/arrow references), reference colouring, F4 | done | +| Point mode (click/drag/arrow references), reference colouring, F4 | done; AutoSum on one cell leaves its proposed range pointed and selected (#1834) | | AutoComplete in columns, function autocomplete and argument tips | done; cell helpers clip to the worksheet and hide when the editor scrolls out (#200) | | Header resize and double-click AutoFit | done (#42, #88 for header dividers) | | Outline symbols for grouped rows / columns (band beside the headers, brackets, − / +, level buttons 1…n+1) | done (#373): clicks run `data.hideDetail` / `data.showDetail` / `data.showLevels`, frozen panes and right-to-left sheets included; summary rows/columns are always below/right (the "Summary rows below detail" setting isn't modelled), no "Show outline symbols" option yet, and a block of cells still groups rows without the Rows / Columns dialog | @@ -161,6 +161,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12. | Date | Change | Summary | |---|---|---| +| 2026-10-20 | minor | AutoSum from the ribbon or keyboard on one cell proposes `=SUM(range)` in the editor instead of entering it, with the range pointed and selected: a click, drag, arrow key or typing replaces it and Enter enters it, as in Excel. With nothing to sum the caret waits inside `=SUM()`. A block still gets its totals at once, and programmatic `formulas.autoSum` is unchanged (#1834) | | 2026-10-19 | minor | Ctrl+Enter (`range.fill`) gives each cell what typing the input there gives: a General cell gets the automatic number format (`5%`, `$5`, `3/4/2026`, `=TODAY()`) even when it already held a value, and a cell with its own format, a formatted row or column, or Text keeps it. Cells that held a value used to keep General (`5%` showed 0.05), and empty cells took the active cell's format | | 2026-10-18 | minor | Keytip letters typed with left Alt held continue the sequence (Alt+H, O, A / Alt+H, O, I ran nothing before: Alt+letter cancelled keytips); other Alt combinations, AltGr and macOS Option are unchanged (#1846) | | 2026-10-12 | minor | The File view's recent list tells when each workbook was last changed, read off the UI thread | From 132bd4e9a8fa99befcae74ef8b7af1910dd6c98f Mon Sep 17 00:00:00 2001 From: kezmdor <15539254+kezmdor@users.noreply.github.com> Date: Tue, 20 Oct 2026 08:59:30 +0200 Subject: [PATCH 2/5] AutoSum: test the menu functions; keep the new editor method clear of #1056 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Home › AutoSum ▾ Average proposes `=AVERAGE(range)` the same way (and so will Formulas › AutoSum once it has the menu, #658). `point_last_argument` moves to the end of `impl EditState`, so this PR no longer touches the lines #1056 and #1838 change after `insert_ref`. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/editor.rs | 34 ++++++++++++++-------------- crates/ui-egui/tests/autosum_edit.rs | 12 ++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/editor.rs b/crates/ui-egui/src/editor.rs index 64fa3627d5..2061a0dbda 100644 --- a/crates/ui-egui/src/editor.rs +++ b/crates/ui-egui/src/editor.rs @@ -110,23 +110,6 @@ impl EditState { self.sync_caret = true; } - /// Points and selects the argument of the call that ends the text, as AutoSum proposes it - /// (`=SUM(B1:B3)`): a click, drag, arrow key or typing replaces `B1:B3`. An arrow key moves - /// from the range's first cell, as in Excel: ↑ on `=SUM(A2:A4)` gives `=SUM(A1)`. With no - /// argument (`=SUM()`) the caret goes between the parentheses. - pub fn point_last_argument(&mut self) { - let Some(open) = self.text.rfind('(') else { return }; - let Some(close) = self.text.len().checked_sub(1).filter(|&c| c > open && self.text.ends_with(')')) else { return }; - let chars = |byte: usize| self.text.get(..byte).map_or(0, |t| t.chars().count()); - let (start, end) = (open + 1, close); - self.caret = chars(end); - self.point = (start < end).then_some((start, end)); - self.select_from = (start < end).then(|| chars(start)); - self.point_cell = self.text.get(start..end).and_then(RangeRef::parse).map(|r| r.start); - self.caret_to_end = false; - self.sync_caret = true; - } - /// Updates function autocomplete for the word before the caret. pub fn update_autocomplete(&mut self, names: &[String]) { self.autocomplete.clear(); @@ -211,6 +194,23 @@ impl EditState { } None } + + /// Points and selects the argument of the call that ends the text, as AutoSum proposes it + /// (`=SUM(B1:B3)`): a click, drag, arrow key or typing replaces `B1:B3`. An arrow key moves + /// from the range's first cell, as in Excel: ↑ on `=SUM(A2:A4)` gives `=SUM(A1)`. With no + /// argument (`=SUM()`) the caret goes between the parentheses. + pub fn point_last_argument(&mut self) { + let Some(open) = self.text.rfind('(') else { return }; + let Some(close) = self.text.len().checked_sub(1).filter(|&c| c > open && self.text.ends_with(')')) else { return }; + let chars = |byte: usize| self.text.get(..byte).map_or(0, |t| t.chars().count()); + let (start, end) = (open + 1, close); + self.caret = chars(end); + self.point = (start < end).then_some((start, end)); + self.select_from = (start < end).then(|| chars(start)); + self.point_cell = self.text.get(start..end).and_then(RangeRef::parse).map(|r| r.start); + self.caret_to_end = false; + self.sync_caret = true; + } } /// References in formula text with their byte spans and colour index (same reference text ⇒ diff --git a/crates/ui-egui/tests/autosum_edit.rs b/crates/ui-egui/tests/autosum_edit.rs index eae1da4079..a1bc0342bf 100644 --- a/crates/ui-egui/tests/autosum_edit.rs +++ b/crates/ui-egui/tests/autosum_edit.rs @@ -79,6 +79,18 @@ fn autosum_on_one_cell_proposes_its_range_in_the_editor() { assert_eq!(h.state().session.active().unwrap().wb.active().unwrap().value(CellRef::parse("A4").unwrap()), Value::Number(6.0)); } +#[test] +fn the_autosum_menu_functions_propose_theirs_the_same_way() { + // Home › AutoSum ▾ Average (and Formulas › AutoSum ▾ once it has the menu, #658). + let mut h = harness("A4"); + h.state_mut().run_or_alert("formulas.autoSum", json!({"function": "AVERAGE"})); + h.run_steps(2); + assert_eq!(editing(&h).as_deref(), Some("=AVERAGE(A1:A3)")); + pointer(&mut h, "A2", true); + pointer(&mut h, "A2", false); + assert_eq!(editing(&h).as_deref(), Some("=AVERAGE(A2)")); +} + #[test] fn a_click_or_drag_replaces_the_proposed_range() { let mut h = harness("A4"); From 601cc60cfcaf15e8f3db0526cbdf26083b4fa4ac Mon Sep 17 00:00:00 2001 From: kezmdor <15539254+kezmdor@users.noreply.github.com> Date: Tue, 20 Oct 2026 09:17:48 +0200 Subject: [PATCH 3/5] AutoSum: a `range` that isn't text counts as no range, as in the engine `formulas.autoSum` reads `range` with `str_param`, so `{"range": null}` means the selection; the UI's check for the editor proposal now reads it the same way (CodeRabbit review). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/lib.rs | 7 ++++++- crates/ui-egui/tests/autosum_edit.rs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 4704ef20d2..1606a85473 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -531,7 +531,10 @@ impl SheetApp { // Menu-style AutoSum on one cell proposes its formula in the editor with the range // pointed and selected, so a click, drag, arrow key or typing replaces it, as in Excel. // Programmatic callers use `run` and get the total entered. - if id == "formulas.autoSum" && params.get("range").is_none() && self.session.active().is_some_and(|d| d.selection.current().is_single()) { + if id == "formulas.autoSum" + && params.get("range").and_then(Json::as_str).is_none() + && self.session.active().is_some_and(|d| d.selection.current().is_single()) + { return self.auto_sum_in_editor(params); } if let Err(e) = self.run(id, params) { @@ -539,6 +542,8 @@ impl SheetApp { } } + /// Runs AutoSum on the active cell without entering it (`enter: false`) and points the + /// proposed range in the editor that opens. fn auto_sum_in_editor(&mut self, params: Json) { let mut params = if params.is_object() { params } else { json!({}) }; if let Some(map) = params.as_object_mut() { diff --git a/crates/ui-egui/tests/autosum_edit.rs b/crates/ui-egui/tests/autosum_edit.rs index a1bc0342bf..9f76bf8a8d 100644 --- a/crates/ui-egui/tests/autosum_edit.rs +++ b/crates/ui-egui/tests/autosum_edit.rs @@ -77,6 +77,12 @@ fn autosum_on_one_cell_proposes_its_range_in_the_editor() { enter(&mut h); assert_eq!(input(&h, "A4"), "=SUM(A1:A3)"); assert_eq!(h.state().session.active().unwrap().wb.active().unwrap().value(CellRef::parse("A4").unwrap()), Value::Number(6.0)); + + // A `range` that isn't text is no range, for the engine and here alike. + let mut h = harness("A4"); + h.state_mut().run_or_alert("formulas.autoSum", json!({"range": null})); + h.run_steps(2); + assert_eq!(editing(&h).as_deref(), Some("=SUM(A1:A3)")); } #[test] From 921cdc974f12b22bc5001e4fd2d2f1ee08051e7d Mon Sep 17 00:00:00 2001 From: kezmdor <15539254+kezmdor@users.noreply.github.com> Date: Sat, 31 Oct 2026 11:59:24 +0100 Subject: [PATCH 4/5] AutoSum tests join the `it` test binary, as main's UI tests do The module uses the shared harness (`common::builder`, `common::app`), so it runs with the pinned font set like the other UI tests. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/tests/{ => it}/autosum_edit.rs | 14 +++----------- crates/ui-egui/tests/it/main.rs | 1 + 2 files changed, 4 insertions(+), 11 deletions(-) rename crates/ui-egui/tests/{ => it}/autosum_edit.rs (93%) diff --git a/crates/ui-egui/tests/autosum_edit.rs b/crates/ui-egui/tests/it/autosum_edit.rs similarity index 93% rename from crates/ui-egui/tests/autosum_edit.rs rename to crates/ui-egui/tests/it/autosum_edit.rs index 9f76bf8a8d..5440fffe02 100644 --- a/crates/ui-egui/tests/autosum_edit.rs +++ b/crates/ui-egui/tests/it/autosum_edit.rs @@ -4,10 +4,10 @@ use egui::{Event, Key, Modifiers, PointerButton, Pos2}; use gridcraft_engine::core::{CellRef, Value}; use gridcraft_engine::{Mode, Session}; -use gridcraft_ui_egui::{SheetApp, grid::Geo}; +use gridcraft_ui_egui::grid::Geo; use serde_json::json; -type Harness = egui_kittest::Harness<'static, SheetApp>; +use crate::common::Harness; /// 1, 2, 3 in A1:A3 and `selected` selected. fn harness(selected: &str) -> Harness { @@ -20,15 +20,7 @@ fn harness_at(first: &str, selected: &str) -> Harness { session.new_workbook(); session.execute("range.setValues", json!({"range": first, "values": [[1], [2], [3]]})).unwrap(); session.execute("selection.set", json!({"range": selected})).unwrap(); - let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SheetApp::new(session, Default::default()), - ); - h.run_steps(4); - h + crate::common::harness_with(crate::common::builder().with_size(egui::vec2(1200.0, 800.0)), crate::common::app(session), 4) } /// The AutoSum button: a menu-style run. diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index 302bc9c49c..d37c238250 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -10,6 +10,7 @@ mod accounting_fill; mod advanced_filter; mod argument_names; mod autosave_persist; +mod autosum_edit; mod borders; mod cell_editor_caret; mod cell_pictures; From def4067247e25191363eca7d2c325c8c39c5f9b6 Mon Sep 17 00:00:00 2001 From: kezmdor <15539254+kezmdor@users.noreply.github.com> Date: Sat, 7 Nov 2026 14:22:50 +0100 Subject: [PATCH 5/5] AutoSum: main's Function Library test expects the proposal in the editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Formulas › AutoSum and its Count Numbers item on one cell now leave `=SUM(A1:A3)` / `=COUNT(B1:B3)` in the editor until Enter, as in Excel (#1834); the test checks the proposal, presses Enter, then the cell. --- crates/ui-egui/tests/it/function_library.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/ui-egui/tests/it/function_library.rs b/crates/ui-egui/tests/it/function_library.rs index a1a7a1a37e..3cb132adc3 100644 --- a/crates/ui-egui/tests/it/function_library.rs +++ b/crates/ui-egui/tests/it/function_library.rs @@ -136,6 +136,10 @@ fn autosum_runs_sum_and_its_arrow_opens_the_shared_menu() { } h.run_steps(2); click(&mut h, "AutoSum"); + // One cell: the proposed formula waits in the editor for Enter, as in Excel (#1834). + assert_eq!(editor_text(&h).as_deref(), Some("=SUM(A1:A3)")); + h.key_press(Key::Enter); + h.run_steps(2); assert_eq!(input(&h, "A4"), "=SUM(A1:A3)"); h.state_mut().session.execute("selection.set", json!({"cell": "B4"})).unwrap(); click(&mut h, "AutoSum options"); @@ -143,6 +147,9 @@ fn autosum_runs_sum_and_its_arrow_opens_the_shared_menu() { h.get_by_label(item); } click(&mut h, "Count Numbers"); + assert_eq!(editor_text(&h).as_deref(), Some("=COUNT(B1:B3)")); + h.key_press(Key::Enter); + h.run_steps(2); assert_eq!(input(&h, "B4"), "=COUNT(B1:B3)"); click(&mut h, "AutoSum options"); click(&mut h, "More Functions…");