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 <noreply@anthropic.com>
This commit is contained in:
kezmdor
2026-10-20 09:18:33 +02:00
co-authored by Claude Opus 5.5
parent 132bd4e9a8
commit 601cc60cfc
2 changed files with 12 additions and 1 deletions
+6 -1
View File
@@ -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() {
+6
View File
@@ -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]