Hide blank and text rows for numeric ordering custom filters

Found while testing crates/engine/src/cmd/data.rs:550 (custom_ok, used from apply_filter at :623)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-18 20:25:07 +02:00
co-authored by Claude Haiku 5.5
parent c30fa3f1cf
commit 4f3853d4a9
2 changed files with 22 additions and 0 deletions
+2
View File
@@ -551,6 +551,8 @@ fn custom_ok(v: &Value, text: &str, op: &str, crit: &str) -> bool {
let num = gridcraft_core::parse::parse_number_text(crit);
let cmp = match (v.as_f64(), num) {
(Some(a), Some(b)) => a.partial_cmp(&b),
// A numeric ordering comparison only matches numbers; blanks and text never do.
(None, Some(_)) if matches!(op, "<" | "<=" | ">" | ">=") => None,
_ => Some(gridcraft_core::compare_text(text, crit)),
};
let wild = || super::edit::wildcard(&text.to_lowercase(), &crit.to_lowercase());
@@ -0,0 +1,20 @@
use gridcraft_engine::Session;
use serde_json::json;
fn visible_rows(op: &str) -> Vec<u32> {
let mut s = Session::new();
s.new_workbook();
s.execute("range.setValues", json!({"range":"A1", "values":[["n"], ["3"], ["10"], [""], ["abc1"], ["20"]]})).unwrap();
s.execute("selection.set", json!({"range":"A1:A6"})).unwrap();
s.execute("data.filter", json!({})).unwrap();
s.execute("data.filterBy", json!({"column":0, "custom":{"op":op, "value":"5"}})).unwrap();
let doc = s.doc().unwrap();
let sh = doc.wb.active().unwrap();
(1..6u32).filter(|r| !sh.rows.get(r).is_some_and(|i| i.hidden)).collect()
}
#[test]
fn less_than_numeric_criterion_hides_blank_and_text_rows() {
assert_eq!(visible_rows("<"), vec![1]);
assert_eq!(visible_rows("<="), vec![1]);
}