From 785913ed47f7c4f33d098a69f1345240b16b54b7 Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Sat, 10 Oct 2026 05:46:21 -0500 Subject: [PATCH] Flash Fill: read the text cells show Flash Fill read stored values, so a date was the serial number 45306, not 2024-01-15: with "15/01/2024" given for 2024-01-15 it found no part of the source in the example and filled every row with "15/01/2024" again. It now reads the cells' displayed text, as Excel does. --- crates/engine/src/fill.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/fill.rs b/crates/engine/src/fill.rs index 5848bb0ca..a80513577 100644 --- a/crates/engine/src/fill.rs +++ b/crates/engine/src/fill.rs @@ -442,13 +442,13 @@ pub fn flash_fill(cx: &mut Ctx, sheet: usize, at: CellRef) -> Result { // Header row: skip a first row whose target is text and source looks like a header? Keep simple. let mut examples = Vec::new(); let mut todo = Vec::new(); + // Flash Fill works on the text cells show (a date as formatted, not its serial number). for r in top..=bottom { - let src = sh.value(CellRef::new(r, src_col)).display(); - let dst = sh.value(CellRef::new(r, at.col)); - if dst.is_empty() { + let src = crate::display::cell_text(&cx.wb, sh, CellRef::new(r, src_col)); + if sh.value(CellRef::new(r, at.col)).is_empty() { todo.push((r, src)); } else { - examples.push((src, dst.display())); + examples.push((src, crate::display::cell_text(&cx.wb, sh, CellRef::new(r, at.col)))); } } if examples.is_empty() { @@ -603,6 +603,18 @@ fn synthesize(src: &str, dst: &str) -> Vec { mod tests { use super::*; + #[test] + fn flash_fill_reads_shown_text() { + let mut s = crate::Session::new(); + s.new_workbook(); + let values = serde_json::json!([["2024-01-15", "15/01/2024"], ["2023-12-03", null]]); + s.execute("range.setValues", serde_json::json!({"range": "A1", "values": values})).unwrap(); + s.execute("selection.set", serde_json::json!({"cell": "B2"})).unwrap(); + s.execute("data.flashFill", serde_json::json!({})).unwrap(); + let sh = s.doc().unwrap().wb.active().unwrap(); + assert_eq!(sh.value(CellRef::new(1, 1)), Value::from("03/12/2023")); + } + #[test] fn flash_programs() { let p = learn(&[("John Smith".into(), "Smith, John".into())]).unwrap();