diff --git a/ROADMAP.md b/ROADMAP.md index 6df4e6c94..aba181775 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -3,7 +3,7 @@ **Stage: alpha** · next: beta, ~25 points of "ready for real work" and ~160–240 h away > **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-16 · **Change:** minor (a selected chart outlines its names, categories and values in Excel's colours, and dragging the values outline's corner changes the chart's data, #4389, #4390; earlier: performance: formula entry and XLSX save win back time lost since 23829d8c (#2654), 465 → 420 ms and 540 → 488 ms on the 100k-row benchmark; Sandbox refuses fcntl's asynchronous notification and the socket ioctls that notify another process on Linux (#3846); CI provisions pinned fonts for coverage tests; the oversized pivot-cache warning's test names the part limit; readiness estimates unchanged) · **Target:** Microsoft Excel (Microsoft 365) -> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-05 · **Change:** minor (CJK fallback text shares the Latin baseline; earlier: form controls: buttons, sliders and spin buttons; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis take ranges by selection on the grid; earlier: Python mode in the formula bar; earlier: Python cells stored and kept in files; earlier: equations: Insert › Equation, editor, gridcraft-math; earlier: What-if and analysis: Solver Sensitivity report for Simplex LP and GRG Nonlinear; earlier: floating objects: one selection, eight resize handles, keyboard delete; earlier: Chart data tables: live source values beneath column, bar, line, area and compatible combo charts; legend keys and borders; XLSX round-trip and print/PDF; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and Insert Function categories; XLSX workbook-view selection, bounded tab ratios and sheet-edit regressions; readiness estimates unchanged; earlier: CSV and text open detects each column's date order, so day-first dates are not silently swapped) · **Target:** Microsoft Excel (Microsoft 365) +> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-05 · **Change:** minor (CJK fallback text shares the Latin baseline; earlier: form controls: buttons, sliders and spin buttons; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis take ranges by selection on the grid; earlier: Python mode in the formula bar; earlier: Python cells stored and kept in files; earlier: equations: Insert › Equation, editor, gridcraft-math; earlier: What-if and analysis: Solver Sensitivity report for Simplex LP and GRG Nonlinear; earlier: floating objects: one selection, eight resize handles, keyboard delete; earlier: Chart data tables: live source values beneath column, bar, line, area and compatible combo charts; legend keys and borders; XLSX round-trip and print/PDF; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and Insert Function categories; XLSX workbook-view selection, bounded tab ratios and sheet-edit regressions; readiness estimates unchanged; earlier: CSV and text open detects each column's date order, so day-first dates are not silently swapped; earlier: searchable data validation dropdown) · **Target:** Microsoft Excel (Microsoft 365) GridCraft aims at full Microsoft Excel parity, and at being better in places: faster, open (XLSX is the native format), fully scriptable by agents (MCP, control channel, CLI), and on the web. @@ -172,6 +172,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in | 2026-10-22 | On the desktop every workbook window is a native window of its own: New, Open and New Window open one, each keeps its own cell draft, dialog and ribbon, and the macOS menu bar acts on the window focused last. Closing one of several windows on a workbook doesn't ask; closing a workbook's last window, or quitting, asks about unsaved changes in that window. The last window closed quits on Windows and Linux; macOS keeps running with the menu bar. First craft-libs `craft-window` use (window list and viewport driver) | | 2026-10-22 | View › New Window opens a second window on the same workbook (it used to open a copy whose Save overwrote the original): each window has its own selection, active sheet and scroll, titles read "Book1:1" / "Book1:2", and Switch Windows, Hide, Unhide and Close act per window. The control channel, CLI `send` and MCP tools take an optional `window` or `doc` id and default to the active window; `window.list` (MCP `list_windows`) lists the windows | | 2026-10-22 | Typing in a cell and then choosing File › New no longer strands the first workbook: the entry is committed into its own workbook before any File or window command (a refused entry stays open and stops the command), View › Switch Windows and the macOS Window menu list the open workbooks with unsaved markers, `view.switchWindows {doc}` switches by a stable workbook id, and the macOS Quit item asks about unsaved workbooks | +| 2026-10-21 | Data validation lists are searchable: typing into the cell filters the dropdown to entries with a word starting with the typed text (case ignored, and the accents of Latin letters such as é, ç, ß, ł, ș, ǎ and Vietnamese ộ: Latin-1, Latin Extended-A and -B, Latin Extended Additional; other scripts keep their marks), and Enter or Tab takes the highlighted entry; `data.validationList` exposes the same search to the CLI, MCP and agents | | 2026-10-21 | Page Setup paper sizes match Japanese Excel: `B4`/`B5`/`B6` are the JIS sizes (ISO B4/B5/B6 stay reachable by name), so a Japanese B5 worksheet prints at 182×257 mm; Japanese Postcard (100×148 mm), Double Postcard (148×200 mm), Envelope #3/#4 (120×235/90×205 mm), Kaku #2/#3 (240×332/216×277 mm) and A6 are added, both sizes reach the PDF page (`file.exportPdf`/`file.print` MediaBox) and the size survives an XLSX round-trip; the Page Layout Size menu lists them. `B4`/`B5` used to be the ISO sizes, which is changed here | | 2026-10-20 | Japanese interface catalog covers every key the Brazilian Portuguese catalog translates: the 398-label shared core plus 545 dialog, message, Backstage and menu strings (943 total, ~43% of ~2,200). A test parses `pt.rs`'s source, so the two catalogs stay in step | | 2026-10-20 | Interface translated into Dutch (518 labels: ribbon, context menus, File view, dialog titles, Options); `nl`, `nl-NL`, `nl-BE` locale tags resolve to Dutch | @@ -309,6 +310,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in | 2026-10-22 | minor | Progress log: a native window per workbook window | | 2026-10-22 | minor | Progress log: New Window shares the workbook; window ids for scripts and MCP | | 2026-10-22 | minor | Progress log: drafts stay in their workbook, Switch Windows, macOS Quit asks to save | +| 2026-10-21 | minor | Progress log: searchable data validation lists | | 2026-10-21 | minor | Page Setup paper sizes: JIS B4/B5/B6 (ISO by name), Japanese postcards and envelopes, A6; PDF page size follows, XLSX round-trips | | 2026-10-20 | minor | Dutch (nl) listed under other shipped languages; progress log row | | 2026-10-19 | minor | Progress log: long flat operator chains (#916) | diff --git a/crates/calc/src/eval.rs b/crates/calc/src/eval.rs index 525440474..d10de1240 100644 --- a/crates/calc/src/eval.rs +++ b/crates/calc/src/eval.rs @@ -265,6 +265,17 @@ impl<'h> Evaluator<'h> { } } + /// Gives this evaluation `work` units instead of [`EVAL_WORK`] (never more than that). + pub fn with_work(mut self, work: u64) -> Self { + self.work = work.min(EVAL_WORK); + self + } + + /// Whether a spend found too little work left (the formula stopped with `#CALC!`). + pub fn is_exhausted(&self) -> bool { + self.exhausted + } + /// Spends `units` of this cell's work; `false` (and nothing left) when there isn't enough. pub(crate) fn spend(&mut self, units: u64) -> bool { match self.work.checked_sub(units) { diff --git a/crates/calc/src/lib.rs b/crates/calc/src/lib.rs index 2f7933d71..794a3f97f 100644 --- a/crates/calc/src/lib.rs +++ b/crates/calc/src/lib.rs @@ -12,7 +12,7 @@ mod trimrange; pub use eval::{Area, SPECIAL_FUNCTIONS, is_known_function}; pub use precision::DisplayedPrecision; -pub use recalc::{Calc, Key, evaluate, now_serial}; +pub use recalc::{Bounded, Calc, Key, evaluate, evaluate_bounded, now_serial}; #[cfg(test)] mod tests; diff --git a/crates/calc/src/recalc.rs b/crates/calc/src/recalc.rs index f38ed8d91..92ea595f1 100644 --- a/crates/calc/src/recalc.rs +++ b/crates/calc/src/recalc.rs @@ -831,6 +831,38 @@ pub fn evaluate_expr(wb: &Workbook, sheet: usize, at: CellRef, expr: &Expr) -> V ev.value(expr) } +/// What [`evaluate_bounded`] found: the formula's reference (not read), its value, or that it ran +/// out of work. +#[derive(Clone, Debug)] +pub enum Bounded { + /// The formula is a reference (`$B$1:$B$9`, a name for one, `OFFSET(…)`): its areas, unread. + Areas(Vec), + Value(Value), + /// The formula needed more than the work it was given. + Exhausted, +} + +/// Evaluates a formula in the context of a cell with at most `work` units of work (one per +/// expression evaluated, per cell read, …), keeping a reference result as its areas so the caller +/// can read as much of them as it needs (a validation list's search source). +pub fn evaluate_bounded(wb: &Workbook, sheet: usize, at: CellRef, formula: &str, work: u64) -> Bounded { + let body = formula.strip_prefix('=').unwrap_or(formula); + let Ok(expr) = gridcraft_formula::parse(body) else { return Bounded::Value(Value::Error(CellError::Name)) }; + let exprs = HashMap::default(); + let mut rng = 0x1234_5678_9ABC_DEF0u64; + let mut host = PassHost::new(wb, &exprs, &mut rng, now_serial()); + let mut ev = Evaluator::new(&mut host, sheet, at).with_work(work); + let r = ev.eval(&expr); + if ev.is_exhausted() { + return Bounded::Exhausted; + } + match r { + crate::eval::Ev::R(areas) => Bounded::Areas(areas), + crate::eval::Ev::V(v) => Bounded::Value(v), + crate::eval::Ev::L(_) => Bounded::Value(Value::Error(CellError::Calc)), + } +} + fn prof_now() -> f64 { gridcraft_core::date::unix_now_ms().unwrap_or(0.0) } diff --git a/crates/engine/src/cmd/data.rs b/crates/engine/src/cmd/data.rs index e6b90d251..2c786bf0a 100644 --- a/crates/engine/src/cmd/data.rs +++ b/crates/engine/src/cmd/data.rs @@ -32,8 +32,11 @@ use sort::{quick_sort, sort}; #[cfg(test)] use tools::split_delimited; use tools::{remove_duplicates, text_to_columns}; -pub use validation::{check_validation, list_items}; -use validation::{circle_invalid, validate_cmd, validation}; +pub use validation::{ + LIST_MATCH_CAP, LIST_SOURCE_BUDGET, ListSource, check_validation, filter_list_items, list_items, list_search_source, search_fold, search_matches, + search_term, +}; +use validation::{circle_invalid, validate_cmd, validation, validation_list_cmd}; pub(super) use validation::{move_rule_formula, moved_rule_parts, remove_rule_cells, remove_validation_cells}; pub fn specs() -> Vec { @@ -99,6 +102,15 @@ pub fn specs() -> Vec { validation ), cmd!(query "data.validate", "Check Value Against Validation", [], None, "{cell?, input} → {ok, message?}", has_doc, validate_cmd), + cmd!( + query "data.validationList", + "Validation List Items", + [], + None, + "{cell?, search?} → {items: [..], truncated} (the cell's list validation entries; `search` keeps those with a word starting with it, ignoring case and the accents of Latin letters; at most 10,000 entries, read from at most 200,000 cells of the source; `truncated`: more may exist)", + has_doc, + validation_list_cmd + ), cmd!(noundo "data.circleInvalid", "Circle Invalid Data", ["Data", "Data Tools", "Data Validation"], None, "{} → {invalid: [cell], truncated: bool (true when the 100,000-cell scan allowance ended before every range was checked)}", has_doc, circle_invalid), CommandSpec { shortcut_mac: Some("Cmd+Shift+K"), diff --git a/crates/engine/src/cmd/data/tests.rs b/crates/engine/src/cmd/data/tests.rs index 524591c94..c4f2eb03b 100644 --- a/crates/engine/src/cmd/data/tests.rs +++ b/crates/engine/src/cmd/data/tests.rs @@ -557,3 +557,144 @@ fn a_rule_with_an_unknown_type_operator_or_error_style_is_refused() { assert_eq!(sh.validations.len(), 3); assert!(check_validation(&s.doc().unwrap().wb, 0, CellRef::parse("A2").unwrap(), "0").is_some()); } + +fn finds(item: &str, typed: &str) -> bool { + search_matches(&search_fold(item), &search_term(typed)) +} + +#[test] +fn list_search_matches_from_a_word_start() { + let la = "Los Angeles - United States of America"; + for ok in ["Los an", " Los an", "Ange", "United St", "united st", "of America", "- United", "", "L"] { + assert!(finds(la, ok), "{ok:?} should match"); + } + for bad in ["United Amer", "geles", "os", "States America", "Los Angeles -"] { + assert!(!finds(la, bad), "{bad:?} should not match"); + } + // A word start can hide behind an earlier, overlapping occurrence. + assert!(finds("xa-a-a", "a-a")); + assert!(finds("(USA)", "usa")); + assert!(finds("2024 report", "202")); +} + +#[test] +fn list_search_ignores_case_and_accents() { + assert!(finds("États-Unis", "etats")); + assert!(finds("États-Unis", "UNIS")); + assert!(finds("Etats-Unis", "États")); + assert!(finds("Straße", "strasse")); + assert!(finds("Œuvre", "oe")); + assert!(finds("Łódź", "lodz")); + // Decomposed accents (e + combining acute) fold the same and don't start a word. + assert!(finds("Cafe\u{301} noir", "café n")); + assert!(!finds("Cafe\u{301}s", "s")); + assert!(finds("東京", "東")); + // Vietnamese (Latin Extended Additional, with ơ/ư from Latin Extended-B), any case. + assert!(finds("Hà Nội - Vietnam", "ha noi")); + assert!(finds("Đà Nẵng", "da nang")); + assert!(finds("Thừa Thiên Huế", "thua thien hue")); + assert!(finds("HỒ CHÍ MINH", "ho chi")); + assert!(finds("Hồ Chí Minh", "HỒ CHÍ")); + assert!(finds("Phường Bến Nghé", "phuong ben")); + // Pinyin tone marks, transliterations with dots below. + assert!(finds("Běijīng", "beijing")); + assert!(finds("Lǜ", "lu")); + assert!(finds("Ḥaifa", "haifa")); + assert_eq!(search_fold("ỆỢỰẠẞ"), "eouass"); +} + +#[test] +fn filter_list_items_keeps_order_and_cap() { + let items: Vec = ["Dubai - United Arab Emirates", "Paris - France", "London - United Kingdom", "Boston - United States"] + .iter() + .map(|s| s.to_string()) + .collect(); + assert_eq!(filter_list_items(&items, "United", 100), [0, 2, 3]); + assert_eq!(filter_list_items(&items, "United St", 100), [3]); + assert_eq!(filter_list_items(&items, "United", 2), [0, 2]); + assert!(filter_list_items(&items, "zzz", 100).is_empty()); +} + +#[test] +fn validation_list_command_returns_filtered_items() { + let mut s = Session::new(); + s.new_workbook(); + s.execute( + "range.setValues", + json!({"range": "E1", "values": [["Paris - France"], ["Dubai - United Arab Emirates"], ["New York - United States"]]}), + ) + .unwrap(); + s.execute("data.validation", json!({"range": "B2:B5", "type": "list", "formula1": "=$E$1:$E$3"})).unwrap(); + let all = s.execute("data.validationList", json!({"cell": "B3"})).unwrap(); + assert_eq!(all["items"].as_array().map(Vec::len), Some(3)); + assert_eq!(all["truncated"], json!(false)); + let some = s.execute("data.validationList", json!({"cell": "B3", "search": "united s"})).unwrap(); + assert_eq!(some["items"], json!(["New York - United States"])); + assert!(s.execute("data.validationList", json!({"cell": "A1"})).is_err(), "no list validation on A1"); + s.execute("data.validation", json!({"range": "C1", "type": "list", "formula1": "\"Été,Hiver\""})).unwrap(); + let lit = s.execute("data.validationList", json!({"cell": "C1", "search": "ete"})).unwrap(); + assert_eq!(lit["items"], json!(["Été"])); +} + +#[test] +fn validation_list_search_reads_a_huge_source_within_its_budget() { + // A list from a whole column used far past the source budget: a search with no match must + // stop at the budget (and say so) rather than read and fold every cell first. + let mut s = Session::new(); + s.new_workbook(); + let rows = LIST_SOURCE_BUDGET + 5_000; + { + let sh = Arc::make_mut(&mut s.doc_mut().unwrap().wb).sheet_mut(0).unwrap(); + for r in 0..rows { + sh.cells.set(CellRef::new(r as u32, 4), Cell::value(Value::Text(format!("Item {r}").into()))); + } + } + s.execute("data.validation", json!({"range": "B2", "type": "list", "formula1": "=$E:$E"})).unwrap(); + let none = s.execute("data.validationList", json!({"cell": "B2", "search": "zzz"})).unwrap(); + assert_eq!(none["items"], json!([])); + assert_eq!(none["truncated"], json!(true), "the source was not read to its end"); + let first = s.execute("data.validationList", json!({"cell": "B2", "search": "item 1"})).unwrap(); + assert_eq!(first["items"][0], json!("Item 1")); + + let wb = s.doc().unwrap().wb.clone(); + let dv = wb.active().unwrap().validations[0].clone(); + let src = list_search_source(&wb, 0, CellRef::new(1, 1), &dv, LIST_SOURCE_BUDGET); + assert!(src.truncated); + assert_eq!(src.items.len(), LIST_SOURCE_BUDGET, "exactly the budget's worth of cells read"); + // The membership check still sees the whole column. + let last = format!("Item {}", rows - 1); + assert!(check_validation(&wb, 0, CellRef::new(1, 1), &last).is_none(), "{last} is in the list"); + // A computed source (a name for a formula) over the same column runs out of formula work instead. + s.execute("formulas.defineName", json!({"name": "Sorted", "refersTo": "=SORT(Sheet1!$E:$E)"})).unwrap(); + s.execute("data.validation", json!({"range": "C2", "type": "list", "formula1": "=Sorted"})).unwrap(); + let sorted = s.execute("data.validationList", json!({"cell": "C2", "search": "zzz"})).unwrap(); + assert_eq!(sorted["truncated"], json!(true)); +} + +#[test] +fn list_search_source_matches_list_items_within_budget() { + let mut s = Session::new(); + s.new_workbook(); + s.execute("range.setValues", json!({"range": "B1:B5", "values": [["a"], [null], ["c"], ["d"], ["e"]]})).unwrap(); + s.execute("cell.set", json!({"cell": "D1", "input": "=SEQUENCE(4)"})).unwrap(); + s.execute("data.validation", json!({"range": "A1:A2", "type": "list", "formula1": "=$B1:$B4"})).unwrap(); + s.execute("data.validation", json!({"range": "C1", "type": "list", "formula1": "=$D$1:$D$9"})).unwrap(); + s.execute("data.validation", json!({"range": "F1", "type": "list", "formula1": "\"x,y,z\""})).unwrap(); + s.execute("formulas.defineName", json!({"name": "Upper", "refersTo": "=UPPER(Sheet1!$B$1:$B$5)"})).unwrap(); + s.execute("data.validation", json!({"range": "G1", "type": "list", "formula1": "=Upper"})).unwrap(); + let wb = s.doc().unwrap().wb.clone(); + let rules = wb.active().unwrap().validations.clone(); + for (dv, cell) in rules.iter().zip(["A2", "C1", "F1", "G1"]) { + let at = CellRef::parse(cell).unwrap(); + let full = list_items(&wb, 0, at, dv); + assert!(!full.is_empty(), "{cell}"); + let src = list_search_source(&wb, 0, at, dv, LIST_SOURCE_BUDGET); + assert_eq!(src, ListSource { items: full.clone(), truncated: false }, "{cell}"); + // A tiny budget keeps the beginning and says the rest was not read. + let cut = list_search_source(&wb, 0, at, dv, 1); + assert!(cut.truncated, "{cell}: {cut:?}"); + assert!(full.starts_with(&cut.items), "{cell}: {cut:?}"); + } + // The spilled SEQUENCE is read cell by cell like stored values. + assert_eq!(list_search_source(&wb, 0, CellRef::new(0, 2), &rules[1], 100).items, ["1", "2", "3", "4"]); +} diff --git a/crates/engine/src/cmd/data/validation.rs b/crates/engine/src/cmd/data/validation.rs index 31f40491d..246cf07ec 100644 --- a/crates/engine/src/cmd/data/validation.rs +++ b/crates/engine/src/cmd/data/validation.rs @@ -269,6 +269,226 @@ pub fn list_items(wb: &Workbook, sheet: usize, at: CellRef, dv: &Validation) -> } } +/// Most entries a searched validation list returns (lists can come from huge ranges). +pub const LIST_MATCH_CAP: usize = 10_000; + +/// Source work a searched validation list may do: cells of its range read (or entries of a literal +/// list, or units of formula work for a computed source). A list from a huge range (`$B:$B` on a +/// sheet used to row 1,048,576) stops here instead of reading every cell, whatever is typed. +pub const LIST_SOURCE_BUDGET: usize = 200_000; + +/// The entries of a list validation read for search, within a source-work budget. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct ListSource { + /// Nonempty entries in list order, up to where the budget ran out. + pub items: Vec, + /// The budget ran out before the whole source was read: `items` is only its beginning. + pub truncated: bool, +} + +/// The entries of a list validation for the cell `at`, as [`list_items`] gives them, but reading at +/// most `budget` units of the source (see [`LIST_SOURCE_BUDGET`]). A range source is walked cell by +/// cell, within the sheet's used range, rather than evaluated into an array first. +pub fn list_search_source(wb: &Workbook, sheet: usize, at: CellRef, dv: &Validation, budget: usize) -> ListSource { + let f = dv.f1.trim(); + if is_literal_list(f) { + // A literal list is bounded by the rule's text; the budget still caps the entries kept. + let mut items = list_items(wb, sheet, at, dv); + let truncated = items.len() > budget; + items.truncate(budget); + return ListSource { items, truncated }; + } + let first = RangeRef::top_left(&dv.ranges).unwrap_or(at); + let work = u64::try_from(budget).unwrap_or(u64::MAX); + match gridcraft_calc::evaluate_bounded(wb, sheet, at, &formula_at(f, first, at), work) { + // One area is read as the evaluator would (several areas or sheets are `#VALUE!`: no list). + gridcraft_calc::Bounded::Areas(areas) => match areas.as_slice() { + [a] => walk_area(wb, a.sheet, a.range, budget), + _ => ListSource::default(), + }, + gridcraft_calc::Bounded::Value(Value::Array(a)) => { + let mut out = ListSource::default(); + for (n, v) in a.data.iter().enumerate() { + if n >= budget { + out.truncated = true; + break; + } + if !v.is_empty() { + out.items.push(v.display()); + } + } + out + } + gridcraft_calc::Bounded::Value(v) if !v.is_empty() && !v.is_error() => ListSource { items: vec![v.display()], truncated: false }, + gridcraft_calc::Bounded::Value(_) => ListSource::default(), + gridcraft_calc::Bounded::Exhausted => ListSource { items: vec![], truncated: true }, + } +} + +/// The nonempty values of `range` on `sheet`, row-major, reading at most `budget` cells. Without +/// spilled values in the range only stored cells are visited; with them, every cell inside the +/// sheet's used range (and the spills) is. Each visited cell counts against the budget. +fn walk_area(wb: &Workbook, sheet: usize, range: RangeRef, budget: usize) -> ListSource { + let mut out = ListSource::default(); + let Some(sh) = wb.sheet(sheet) else { return out }; + let spilled = sh.spill_ranges.values().filter_map(|r| r.intersection(&range)).collect::>(); + let mut seen = 0usize; + let mut take = |v: &Value, out: &mut ListSource| { + if seen >= budget { + out.truncated = true; + return false; + } + seen += 1; + if !v.is_empty() { + out.items.push(v.display()); + } + true + }; + if spilled.is_empty() { + for (_, cell) in sh.cells.iter_range(range) { + if !take(&cell.value, &mut out) { + break; + } + } + } else { + let extent = spilled.iter().fold(sh.used_range(), |u, r| Some(u.map_or(*r, |u| u.union(r)))); + let Some(range) = extent.and_then(|u| u.intersection(&range)) else { return out }; + for c in range.iter() { + if !take(&sh.value(c), &mut out) { + break; + } + } + } + out +} + +/// Text folded for list search: lower case, with the accents of Latin letters removed +/// (`É` → `e`, `ß` → `ss`, `Œ` → `oe`, `Ộ` → `o`) and combining marks dropped. Covers Latin-1, +/// Latin Extended-A and -B and Latin Extended Additional; other scripts keep their marks. +pub fn search_fold(s: &str) -> String { + let mut out = String::with_capacity(s.len()); + for ch in s.chars().flat_map(char::to_lowercase) { + match fold_latin(ch) { + Some(f) => out.push_str(f), + None => out.push(ch), + } + } + out +} + +/// The unaccented spelling of a lower-case Latin letter (`é` → `e`, `ß` → `ss`, `ộ` → `o`); +/// combining marks fold to nothing. `None` leaves the character as it is. +fn fold_latin(c: char) -> Option<&'static str> { + Some(match c { + '\u{300}'..='\u{36f}' => "", + 'à'..='å' | 'ā' | 'ă' | 'ą' => "a", + 'æ' => "ae", + 'ç' | 'ć' | 'ĉ' | 'ċ' | 'č' => "c", + 'ð' | 'ď' | 'đ' => "d", + 'è'..='ë' | 'ē' | 'ĕ' | 'ė' | 'ę' | 'ě' => "e", + 'ĝ' | 'ğ' | 'ġ' | 'ģ' => "g", + 'ĥ' | 'ħ' => "h", + 'ì'..='ï' | 'ĩ' | 'ī' | 'ĭ' | 'į' | 'ı' => "i", + 'ĵ' => "j", + 'ķ' => "k", + 'ĺ' | 'ļ' | 'ľ' | 'ŀ' | 'ł' => "l", + 'ñ' | 'ń' | 'ņ' | 'ň' => "n", + 'ò'..='ö' | 'ø' | 'ō' | 'ŏ' | 'ő' => "o", + 'œ' => "oe", + 'ŕ' | 'ŗ' | 'ř' => "r", + 'ś' | 'ŝ' | 'ş' | 'š' | 'ș' => "s", + 'ß' => "ss", + 'ţ' | 'ť' | 'ŧ' | 'ț' => "t", + 'þ' => "th", + 'ù'..='ü' | 'ũ' | 'ū' | 'ŭ' | 'ů' | 'ű' | 'ų' => "u", + 'ŵ' => "w", + 'ý' | 'ÿ' | 'ŷ' => "y", + 'ź' | 'ż' | 'ž' => "z", + // Latin Extended-B and Latin Extended Additional (Vietnamese, pinyin tones, …): the base + // letter of each canonical decomposition (Unicode 15). + 'ǎ' | 'ǟ' | 'ǡ' | 'ǻ' | 'ȁ' | 'ȃ' | 'ȧ' | 'ḁ' | 'ạ' | 'ả' | 'ấ' | 'ầ' | 'ẩ' | 'ẫ' | 'ậ' | 'ắ' | 'ằ' | 'ẳ' | 'ẵ' | 'ặ' => { + "a" + } + 'ḃ' | 'ḅ' | 'ḇ' => "b", + 'ḉ' => "c", + 'ḋ' | 'ḍ' | 'ḏ' | 'ḑ' | 'ḓ' => "d", + 'ȅ' | 'ȇ' | 'ȩ' | 'ḕ' | 'ḗ' | 'ḙ' | 'ḛ' | 'ḝ' | 'ẹ' | 'ẻ' | 'ẽ' | 'ế' | 'ề' | 'ể' | 'ễ' | 'ệ' => "e", + 'ḟ' => "f", + 'ǧ' | 'ǵ' | 'ḡ' => "g", + 'ȟ' | 'ḣ' | 'ḥ' | 'ḧ' | 'ḩ' | 'ḫ' | 'ẖ' => "h", + 'ǐ' | 'ȉ' | 'ȋ' | 'ḭ' | 'ḯ' | 'ỉ' | 'ị' => "i", + 'ǰ' => "j", + 'ǩ' | 'ḱ' | 'ḳ' | 'ḵ' => "k", + 'ḷ' | 'ḹ' | 'ḻ' | 'ḽ' => "l", + 'ḿ' | 'ṁ' | 'ṃ' => "m", + 'ǹ' | 'ṅ' | 'ṇ' | 'ṉ' | 'ṋ' => "n", + 'ơ' | 'ǒ' | 'ǫ' | 'ǭ' | 'ȍ' | 'ȏ' | 'ȫ' | 'ȭ' | 'ȯ' | 'ȱ' | 'ṍ' | 'ṏ' | 'ṑ' | 'ṓ' | 'ọ' | 'ỏ' | 'ố' | 'ồ' | 'ổ' | 'ỗ' | 'ộ' | 'ớ' | 'ờ' + | 'ở' | 'ỡ' | 'ợ' => "o", + 'ṕ' | 'ṗ' => "p", + 'ȑ' | 'ȓ' | 'ṙ' | 'ṛ' | 'ṝ' | 'ṟ' => "r", + 'ṡ' | 'ṣ' | 'ṥ' | 'ṧ' | 'ṩ' => "s", + 'ṫ' | 'ṭ' | 'ṯ' | 'ṱ' | 'ẗ' => "t", + 'ư' | 'ǔ' | 'ǖ' | 'ǘ' | 'ǚ' | 'ǜ' | 'ȕ' | 'ȗ' | 'ṳ' | 'ṵ' | 'ṷ' | 'ṹ' | 'ṻ' | 'ụ' | 'ủ' | 'ứ' | 'ừ' | 'ử' | 'ữ' | 'ự' => { + "u" + } + 'ṽ' | 'ṿ' => "v", + 'ẁ' | 'ẃ' | 'ẅ' | 'ẇ' | 'ẉ' | 'ẘ' => "w", + 'ẋ' | 'ẍ' => "x", + 'ȳ' | 'ẏ' | 'ẙ' | 'ỳ' | 'ỵ' | 'ỷ' | 'ỹ' => "y", + 'ẑ' | 'ẓ' | 'ẕ' => "z", + _ => return None, + }) +} + +/// The search term as typed, folded for [`search_matches`]. Leading spaces are ignored. +pub fn search_term(typed: &str) -> String { + search_fold(typed.trim_start()) +} + +/// Whether a folded list entry matches a folded search term, as Excel's in-cell list search: +/// the term appears as one piece that starts at the beginning of a word ("United St" finds +/// "Los Angeles - United States", "geles" and "United Amer" don't). +pub fn search_matches(folded_item: &str, folded_term: &str) -> bool { + if folded_term.is_empty() { + return true; + } + let mut prev: Option = None; + for (i, ch) in folded_item.char_indices() { + if prev.is_none_or(|p| !p.is_alphanumeric()) && folded_item.get(i..).is_some_and(|rest| rest.starts_with(folded_term)) { + return true; + } + prev = Some(ch); + } + false +} + +/// Indices of the list entries matching `typed`, in list order, at most `cap` of them. +pub fn filter_list_items(items: &[String], typed: &str, cap: usize) -> Vec { + let term = search_term(typed); + items.iter().enumerate().filter(|(_, it)| search_matches(&search_fold(it), &term)).map(|(i, _)| i).take(cap).collect() +} + +/// `data.validationList`: a cell's list validation entries, searched like the in-cell dropdown, +/// at most [`LIST_MATCH_CAP`] of them, from at most [`LIST_SOURCE_BUDGET`] of source work. +/// `truncated` says that more entries may exist (past the match cap, or past the source budget). +pub(super) fn validation_list_cmd(s: &mut Session, p: &Json) -> Result { + let d = s.doc()?; + let at = cell_param(s, p, "cell")?.unwrap_or(d.selection.active); + let sheet = d.wb.active_sheet(); + let dv = + d.wb.sheet(sheet) + .and_then(|sh| sh.validations.iter().find(|v| v.kind == ValidationKind::List && v.ranges.iter().any(|r| r.contains(at)))) + .ok_or_else(|| EngineError::Other(format!("{} has no list validation", at.a1())))?; + let ListSource { items, truncated: source_truncated } = list_search_source(&d.wb, sheet, at, dv, LIST_SOURCE_BUDGET); + let picked: Vec = match str_param(p, "search") { + Some(term) => filter_list_items(&items, term, LIST_MATCH_CAP.saturating_add(1)), + None => (0..items.len().min(LIST_MATCH_CAP.saturating_add(1))).collect(), + }; + let truncated = source_truncated || picked.len() > LIST_MATCH_CAP; + let out: Vec<&String> = picked.iter().take(LIST_MATCH_CAP).filter_map(|&i| items.get(i)).collect(); + Ok(json!({"items": out, "truncated": truncated})) +} + /// Checks typed input against the validation of a cell. `Ok(None)` = valid. pub fn check_validation(wb: &Workbook, sheet: usize, at: CellRef, input: &str) -> Option<(Validation, String)> { let sh = wb.sheet(sheet)?; diff --git a/crates/ui-egui/src/app/editing.rs b/crates/ui-egui/src/app/editing.rs index 078f840c0..6e1ba01a2 100644 --- a/crates/ui-egui/src/app/editing.rs +++ b/crates/ui-egui/src/app/editing.rs @@ -71,9 +71,23 @@ impl SheetApp { let mut ed = editor::EditState::new(d.uid, d.wb.active_sheet(), at, text, replace, from_formula_bar).on_sheet(&d.wb); ed.window = self.session.active_window(); ed.locale = locale; - if replace && self.ui.autocomplete && !ed.is_formula() { + // A list validation with an in-cell dropdown is searched as the user types; its list + // replaces column AutoComplete. + let list = sh + .validations + .iter() + .find(|v| v.kind == gridcraft_engine::model::ValidationKind::List && v.in_cell_dropdown && v.ranges.iter().any(|r| r.contains(at))); + if let Some(dv) = list { + // Read within a budget: a list from a huge range must not stall the edit it opens. + let budget = gridcraft_engine::cmd::data::LIST_SOURCE_BUDGET; + ed.set_list_source(gridcraft_engine::cmd::data::list_search_source(&d.wb, d.wb.active_sheet(), at, dv, budget), replace); + } else if replace && self.ui.autocomplete && !ed.is_formula() { ed.completion = editor::column_completion(sh, at, &ed.text); } + // Typing over an open dropdown list hands over to the searched list the edit shows; the + // entries it read (and the workbook version they pin) go with it. + self.grid.list_picker = None; + self.grid.list_picker_items = None; self.editor = Some(ed); self.session.mode = if replace { gridcraft_engine::Mode::Enter } else { gridcraft_engine::Mode::Edit }; } @@ -137,9 +151,13 @@ impl SheetApp { if !self.follow_draft_sheet(&mut ed) { return true; } - let text = match &ed.completion { + // Only an explicit acceptance takes the list's entry; a failed commit asks again. + let accepted = std::mem::take(&mut ed.list_accept); + let text = match (ed.list_choice().filter(|_| accepted), &ed.completion) { + // The searched validation list's highlighted entry, as the list spells it. + (Some(choice), _) => choice.to_string(), // A code edit commits the code as typed, whatever a completion holds. - Some(full) if !ed.python && full.to_lowercase().starts_with(&ed.text.to_lowercase()) => full.clone(), + (None, Some(full)) if !ed.python && full.to_lowercase().starts_with(&ed.text.to_lowercase()) => full.clone(), _ => ed.text.clone(), }; // F2 then Enter (or a file command) on an untouched draft: nothing to write. diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 7d7daf006..75ccf2f4b 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -390,6 +390,7 @@ pub fn handle(app: &mut SheetApp, ctx: &egui::Context, method: &str, p: &Json) - Some(e) => { e.text = s("text").unwrap_or("").to_string(); e.caret = e.text.chars().count(); + e.update_list(); ok(Json::Null) } None => err("not editing"), diff --git a/crates/ui-egui/src/editor.rs b/crates/ui-egui/src/editor.rs index 71fd2a170..0a9d9a99c 100644 --- a/crates/ui-egui/src/editor.rs +++ b/crates/ui-egui/src/editor.rs @@ -59,11 +59,54 @@ pub struct EditState { /// The cell's text when an F2-style edit began. Committing it unchanged leaves the cell alone /// (no undo step, the workbook stays clean). `None` for an edit started by typing. pub original: Option, + /// The searchable list of a cell with an in-cell list validation dropdown. + pub list: Option, + /// The user accepted the list's highlighted entry (Enter, Tab or a click on it). Any other + /// commit (clicking elsewhere, a ribbon command, saving) keeps the typed text. + pub list_accept: bool, /// Python mode: the text is a Python cell's code, edited in the formula bar's code editor and /// committed with Ctrl+Enter (Cmd+Enter on macOS) through `python.set`. pub python: bool, } +/// Entries of a list validation, searched as the user types (Excel's searchable dropdown). +#[derive(Clone, Debug, Default)] +pub struct ListSearch { + pub items: Vec, + /// `items` folded for search once, so each keystroke only compares. + folded: Vec, + /// Indices into `items` of the entries matching the typed text, in list order. + pub matches: Vec, + /// The highlighted entry, an index into `matches`. + pub index: usize, + /// Closed with Escape: hidden until the text changes again. + pub closed: bool, + /// First visible row of the popup (an index into `matches`). + pub top: usize, + /// The highlight moved: scroll the popup so it shows. + pub reveal: bool, + /// The list's source was longer than its read budget: `items` holds only its beginning. + pub truncated: bool, + /// Width of the longest of the first matches as the popup measured it, so it is laid out once + /// per search rather than every frame. `None` until measured, and again when the matches change. + pub text_width: Option, +} + +impl ListSearch { + /// Rows the popup shows at once. + pub const VISIBLE: usize = 8; + + /// Scrolls `top` just enough to show the highlighted row. + fn keep_visible(&mut self) { + if self.index < self.top { + self.top = self.index; + } else if self.index >= self.top.saturating_add(Self::VISIBLE) { + self.top = self.index.saturating_add(1).saturating_sub(Self::VISIBLE); + } + self.reveal = true; + } +} + /// A digest of the order of `wb`'s sheets by identity: it changes when a sheet is inserted, /// deleted or moved, not when one is renamed or edited. pub fn sheet_order(wb: &gridcraft_engine::model::Workbook) -> u64 { @@ -99,10 +142,97 @@ impl EditState { caret_to_end: true, completion: None, original, + list: None, + list_accept: false, python: false, } } + /// Gives this edit the entries of its cell's list validation. `search_now` filters them + /// against the text right away (an edit started by typing); otherwise the list waits for + /// the first change (F2 on an existing value). + pub fn set_list_items(&mut self, items: Vec, search_now: bool) { + let folded = items.iter().map(|i| gridcraft_engine::cmd::data::search_fold(i)).collect(); + self.list = Some(ListSearch { items, folded, ..Default::default() }); + if search_now { + self.update_list(); + } + } + + /// Gives this edit a list read within the source budget + /// ([`gridcraft_engine::cmd::data::list_search_source`]), remembering whether it was cut short. + pub fn set_list_source(&mut self, source: gridcraft_engine::cmd::data::ListSource, search_now: bool) { + self.set_list_items(source.items, search_now); + if let Some(l) = self.list.as_mut() { + l.truncated = source.truncated; + } + } + + /// Refilters the list against the typed text (call when the text changes). + pub fn update_list(&mut self) { + let typed = if self.is_formula() || self.text.trim().is_empty() { None } else { Some(self.text.as_str()) }; + let Some(list) = self.list.as_mut() else { return }; + list.matches.clear(); + list.text_width = None; + list.index = 0; + list.top = 0; + list.reveal = true; + list.closed = false; + let Some(typed) = typed else { return }; + let term = gridcraft_engine::cmd::data::search_term(typed); + let cap = gridcraft_engine::cmd::data::LIST_MATCH_CAP; + // Text naming an entry exactly highlights that entry rather than the first match. The + // kept matches stay the first `cap` in list order (as `data.validationList` returns), so + // an exact entry past the cap isn't shown. + let whole = gridcraft_engine::cmd::data::search_fold(typed.trim()); + let mut exact = None; + for (i, f) in list.folded.iter().enumerate() { + if list.matches.len() >= cap { + break; + } + if !gridcraft_engine::cmd::data::search_matches(f, &term) { + continue; + } + if exact.is_none() && *f == whole { + exact = Some(list.matches.len()); + } + list.matches.push(i); + } + if let Some(pos) = exact { + list.index = pos; + list.keep_visible(); + } + } + + /// Whether the searched list is showing (it has matches and wasn't closed). + pub fn list_open(&self) -> bool { + self.list.as_ref().is_some_and(|l| !l.closed && !l.matches.is_empty()) + } + + /// The highlighted entry of the open list: what Enter or Tab commits (see `list_accept`). + pub fn list_choice(&self) -> Option<&str> { + let l = self.list.as_ref().filter(|_| self.list_open())?; + l.matches.get(l.index).and_then(|&i| l.items.get(i)).map(String::as_str) + } + + /// Moves the highlight down (or up), wrapping around. + pub fn list_step(&mut self, down: bool) { + if let Some(l) = self.list.as_mut() + && !l.matches.is_empty() + { + let n = l.matches.len(); + l.index = if down { (l.index + 1) % n } else { (l.index + n - 1) % n }; + l.keep_visible(); + } + } + + /// Hides the list until the text changes (Escape). + pub fn close_list(&mut self) { + if let Some(l) = self.list.as_mut() { + l.closed = true; + } + } + /// An edit of a cell's Python code, in the formula bar. pub fn python(doc: u64, sheet: usize, cell: CellRef, code: String) -> EditState { let mut ed = EditState::new(doc, sheet, cell, code, false, true); @@ -150,6 +280,7 @@ impl EditState { self.point_anchor = None; self.autocomplete.clear(); self.completion = None; + self.list = None; self.caret = self.text.chars().count(); self.anchor = self.caret; self.caret_to_end = false; @@ -541,6 +672,119 @@ mod tests { assert!(ref_is_on_sheet(Some("sheet2"), "Sheet1", "Sheet2"), "sheet names compare ignoring case"); } + fn cities() -> Vec { + ["Dubai - United Arab Emirates", "Paris - France", "London - United Kingdom", "Boston - United States", "Los Angeles - United States"] + .iter() + .map(|s| s.to_string()) + .collect() + } + + fn typed(text: &str) -> EditState { + let mut e = EditState::new(1, 0, CellRef::new(0, 0), text.into(), true, false); + e.set_list_items(cities(), true); + e + } + + #[test] + fn list_search_filters_as_typed_and_picks_the_first_match() { + let mut e = typed("u"); + assert!(e.list_open()); + e.text = "United".into(); + e.update_list(); + assert_eq!(e.list.as_ref().map(|l| l.matches.clone()), Some(vec![0, 2, 3, 4])); + assert_eq!(e.list_choice(), Some("Dubai - United Arab Emirates")); + e.text = "united st".into(); + e.update_list(); + assert_eq!(e.list_choice(), Some("Boston - United States")); + e.list_step(true); + assert_eq!(e.list_choice(), Some("Los Angeles - United States")); + e.list_step(true); + assert_eq!(e.list_choice(), Some("Boston - United States"), "the highlight wraps"); + e.list_step(false); + assert_eq!(e.list_choice(), Some("Los Angeles - United States")); + } + + #[test] + fn list_search_hides_without_matches_formulas_or_text() { + assert!(!typed("Tokyo").list_open()); + assert!(!typed("=A1").list_open()); + assert!(!typed(" ").list_open()); + assert_eq!(typed("Tokyo").list_choice(), None); + } + + #[test] + fn list_search_escape_closes_until_the_text_changes() { + let mut e = typed("Par"); + e.close_list(); + assert!(!e.list_open()); + assert_eq!(e.list_choice(), None, "a closed list commits the typed text"); + e.text = "Pari".into(); + e.update_list(); + assert_eq!(e.list_choice(), Some("Paris - France")); + } + + #[test] + fn list_search_prefers_an_exact_entry() { + let mut e = EditState::new(1, 0, CellRef::new(0, 0), "paris".into(), true, false); + e.set_list_items(vec!["Paris - France".into(), "Paris".into()], true); + assert_eq!(e.list_choice(), Some("Paris")); + } + + #[test] + fn list_search_waits_for_a_change_when_editing_an_existing_value() { + let mut e = EditState::new(1, 0, CellRef::new(0, 0), "Paris - France".into(), false, false); + e.set_list_items(cities(), false); + assert!(!e.list_open(), "F2 doesn't pop the list up"); + e.text = "Paris".into(); + e.update_list(); + assert!(e.list_open()); + } + + #[test] + fn list_search_keeps_the_highlight_in_view() { + let items: Vec = (0..20).map(|i| format!("Item {i}")).collect(); + let mut e = EditState::new(1, 0, CellRef::new(0, 0), "item".into(), true, false); + e.set_list_items(items, true); + for _ in 0..10 { + e.list_step(true); + } + let l = e.list.as_ref().map(|l| (l.index, l.top)).unwrap_or_default(); + assert_eq!(l, (10, 10 + 1 - ListSearch::VISIBLE)); + e.list_step(false); + e.list_step(false); + e.list_step(false); + e.list_step(false); + e.list_step(false); + e.list_step(false); + e.list_step(false); + let l = e.list.as_ref().map(|l| (l.index, l.top)).unwrap_or_default(); + assert_eq!(l, (3, 3)); + } + + #[test] + fn list_search_keeps_list_order_when_the_exact_entry_is_past_the_cap() { + let cap = gridcraft_engine::cmd::data::LIST_MATCH_CAP; + let mut items: Vec = (0..cap + 5).map(|i| format!("Item {i}")).collect(); + items.push("Item".into()); + let mut e = EditState::new(1, 0, CellRef::new(0, 0), "item".into(), true, false); + e.set_list_items(items, true); + let (matches, index) = e.list.as_ref().map(|l| (l.matches.clone(), l.index)).unwrap_or_default(); + assert_eq!(matches, (0..cap).collect::>(), "the first `cap` matches, in list order"); + assert_eq!(index, 0, "the first match stays highlighted"); + assert_eq!(e.list_choice(), Some("Item 0")); + } + + #[test] + fn list_search_highlights_an_exact_entry_within_the_cap() { + let items: Vec = (0..20).map(|i| format!("Item {i}")).chain(["Item".to_string()]).collect(); + let mut e = EditState::new(1, 0, CellRef::new(0, 0), "item".into(), true, false); + e.set_list_items(items, true); + let (index, top) = e.list.as_ref().map(|l| (l.index, l.top)).unwrap_or_default(); + assert_eq!(index, 20); + assert_eq!(top, 21 - ListSearch::VISIBLE, "scrolled into view"); + assert_eq!(e.list_choice(), Some("Item")); + } + #[test] fn whole_row_and_column_ref_spans() { let refs = formula_refs("=SUM(C:C,4:6,$D:$E,Sheet2!7:8)"); diff --git a/crates/ui-egui/src/formula_bar.rs b/crates/ui-egui/src/formula_bar.rs index 5d5498652..c0805c78c 100644 --- a/crates/ui-egui/src/formula_bar.rs +++ b/crates/ui-egui/src/formula_bar.rs @@ -116,6 +116,10 @@ pub fn show(app: &mut SheetApp, ui: &mut egui::Ui) { app.cancel_edit(); } if crate::widgets::icon_button(ui, Icon::Check, c, "Enter", vec2(22.0, 24.0)).clicked() && editing { + // The Enter button is Enter: it takes the searched list's highlighted entry. + if let Some(ed) = app.editor.as_mut() { + ed.list_accept = true; + } app.commit_edit(0, 0, false, false); } let fx = crate::widgets::icon_button(ui, Icon::Fx, t.text, "Insert Function", vec2(26.0, 24.0)); @@ -590,8 +594,10 @@ pub fn editor_widget(app: &mut SheetApp, ui: &mut egui::Ui, id: egui::Id, font: } if resp.changed() { ed.completion = None; + ed.update_list(); // Python code is never completed from the column's text values. if app.ui.autocomplete + && ed.list.is_none() && !ed.is_formula() && !ed.python && !entry_shrank(chars_before, &ed.text) @@ -715,11 +721,18 @@ fn editor_confirm_keys(ui: &mut egui::Ui, ed: &mut crate::editor::EditState) -> if cmd_enter { action = Some((0, 0, false, true)); } + // Enter, Tab and Ctrl+Enter accept the searched list's highlighted entry. + if action.is_some() { + ed.list_accept = true; + } if ctrl_shift_enter { action = Some((0, 0, true, false)); } let cancel = if !esc { false + } else if ed.list_open() { + ed.close_list(); + false } else if !ed.autocomplete.is_empty() { ed.autocomplete.clear(); false @@ -755,6 +768,15 @@ fn editor_arrow_keys( arrow.is_some_and(|(k, _)| k == Key::ArrowRight), ); let (shift, jump) = arrow.map_or((false, false), |(_, m)| (m.shift, m.command)); + if (up || down) && !shift && ed.list_open() { + // The searched validation list takes Up/Down, even in Enter mode. + ui.input_mut(|i| { + i.consume_key(egui::Modifiers::NONE, Key::ArrowUp); + i.consume_key(egui::Modifiers::NONE, Key::ArrowDown); + }); + ed.list_step(down); + return (action, false); + } if (up || down) && !ed.autocomplete.is_empty() { ui.input_mut(|i| { i.consume_key(egui::Modifiers::NONE, Key::ArrowUp); diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index 477a4e26a..c52875a24 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -26,7 +26,7 @@ mod active_row; pub use active_row::active_row_band; mod cell_paint; mod cursor; -mod editor; +pub(crate) mod editor; mod geo; mod interact; mod keyboard; @@ -251,6 +251,16 @@ impl Trace { } } +/// The entries of an open list-validation dropdown, read within the list search budget +/// ([`gridcraft_engine::cmd::data::LIST_SOURCE_BUDGET`]). +pub struct ListPickerItems { + /// The workbook version they were read from: any edit makes a new one. + pub(crate) wb: std::sync::Arc, + pub(crate) sheet: usize, + pub(crate) cell: CellRef, + pub source: gridcraft_engine::cmd::data::ListSource, +} + #[derive(Default)] pub struct GridState { /// The active sheet's line positions and outlines, kept with a weak reference to the sheet @@ -304,6 +314,9 @@ pub struct GridState { pub renaming_tab: Option, pub rename_text: String, pub list_picker: Option, + /// The open dropdown's entries, read once for the workbook, sheet and cell they came from, so + /// an open list doesn't read its source again every frame. + pub list_picker_items: Option, /// Open task pane: comments, watch, selection, formatChart. pub pane: Option, /// Ink stroke being drawn (sheet points). diff --git a/crates/ui-egui/src/grid/editor.rs b/crates/ui-egui/src/grid/editor.rs index 72b7cc7bb..28fb89fc5 100644 --- a/crates/ui-egui/src/grid/editor.rs +++ b/crates/ui-egui/src/grid/editor.rs @@ -1,6 +1,8 @@ use super::cell_paint::ink_on; use super::geo::Geo; -use super::{Align2, CellRef, Color32, FontId, PatternType, Rect, Sheet, SheetApp, Stroke, StrokeKind, Tokens, Workbook, json, pos2, theme, vec2}; +use super::{ + Align2, Arc, CellRef, Color32, FontId, PatternType, Rect, Sheet, SheetApp, Stroke, StrokeKind, Tokens, Workbook, json, pos2, theme, vec2, +}; /// Room the in-cell editor keeps right of its text. It is sized from the text of the last frame, so /// the next typed character must still fit: a fixed 14 px was less than one glyph at high zoom, @@ -108,6 +110,117 @@ const LIST_PICKER_ROW_H: f32 = 18.0; /// Popup frame around the rows: 2 px inner margin and the window stroke on each side, rounded up. const LIST_PICKER_CHROME: f32 = 8.0; +/// Shown under a validation list that was cut short (source budget or match cap). +pub(crate) const LIST_MORE_NOTE: &str = "More entries not shown"; + +/// Height of one row of a validation list popup: its button's real height (text plus padding), at +/// least `LIST_PICKER_ROW_H`. `show_rows` needs the height the rows are drawn at: with a smaller +/// one the popup shows fewer rows than it scrolls by and the last entries can't be reached. +fn list_row_height(ui: &egui::Ui) -> f32 { + LIST_PICKER_ROW_H.max(ui.text_style_height(&egui::TextStyle::Button) + 2.0 * ui.spacing().button_padding.y).ceil() +} + +/// Draws one row of a validation list popup in a slot exactly `row_h` tall. A button sizes itself +/// to its text, and text is laid out to the tallest face its glyphs fall back to, rounded to whole +/// pixels, so its height is not always `list_row_height`. `show_rows` places rows by `row_h`: rows +/// that advance by anything else drift out of the popup and under the note below it. +fn list_row(ui: &mut egui::Ui, width: f32, row_h: f32, button: egui::Button<'_>) -> egui::Response { + let (slot, _) = ui.allocate_exact_size(vec2(width, row_h), egui::Sense::hover()); + // A child placed on the slot: whatever the button asks for, the popup advances by the slot. + let mut row = ui.new_child(egui::UiBuilder::new().max_rect(slot).layout(egui::Layout::top_down(egui::Align::Min))); + row.add(button.min_size(slot.size())) +} + +/// The searched list of a list validation under the cell being typed into (from the cell or the +/// formula bar): the matches of the typed text, the highlighted one is what Enter commits. +pub(super) fn list_search(app: &mut SheetApp, ui: &mut egui::Ui, geo: &Geo, sh: &Sheet) { + let view = app.view_key(); + let Some(ed) = app.editor.as_mut() else { return }; + if view != Some((ed.doc, ed.sheet)) || !ed.list_open() || geo.hidden_under_frozen(sh, ed.cell) { + return; + } + let r = match sh.merge_at(ed.cell) { + Some(m) => geo.range_rect(sh, m), + None => geo.cell_rect(sh, ed.cell), + }; + if !geo.cells.intersects(r) { + return; + } + let Some(list) = ed.list.as_mut() else { return }; + // Rows are as tall as their buttons really are, so `show_rows` places them where they are + // drawn: the popup shows `ListSearch::VISIBLE` of them and the highlighted one stays in view. + let row_h = list_row_height(ui); + // Wide enough for the longest of the first matches, within reason. Measured once per search: + // `update_list` clears it when the matches change. + let longest = match list.text_width { + Some(w) => w, + None => { + let font = egui::TextStyle::Button.resolve(ui.style()); + let w = list + .matches + .iter() + .take(200) + .filter_map(|&i| list.items.get(i)) + .map(|t| ui.painter().layout_no_wrap(t.clone(), font.clone(), Color32::BLACK).size().x) + .fold(0.0_f32, f32::max); + list.text_width = Some(w); + w + } + }; + let width = r.width().max(100.0).max((longest + 16.0).min(480.0)); + // Not every entry was searched (a huge source) or shown (past the match cap). + let more = list.truncated || list.matches.len() >= gridcraft_engine::cmd::data::LIST_MATCH_CAP; + let height = row_h * list.matches.len().clamp(1, crate::editor::ListSearch::VISIBLE) as f32; + let note = if more { row_h } else { 0.0 }; + // Below the cell, or above it when the rows would run past the bottom of the window (as the + // dropdown arrow's list does). + let screen = ui.ctx().content_rect(); + let outer = height + note + LIST_PICKER_CHROME; + let above = r.bottom() + outer > screen.bottom() && r.top() - outer >= screen.top(); + let (at, pivot) = match (above, geo.rtl) { + (false, false) => (geo.mirror_pos(r.left_bottom()), Align2::LEFT_TOP), + (false, true) => (geo.mirror_pos(r.left_bottom()), Align2::RIGHT_TOP), + (true, false) => (geo.mirror_pos(r.left_top()), Align2::LEFT_BOTTOM), + (true, true) => (geo.mirror_pos(r.left_top()), Align2::RIGHT_BOTTOM), + }; + let reveal = std::mem::take(&mut list.reveal).then_some(list.top as f32 * row_h); + let lang = crate::i18n::current(ui.ctx()); + let mut pick = None; + let mut top = None; + egui::Area::new(egui::Id::unique("dv_search")).fixed_pos(at).pivot(pivot).order(egui::Order::Foreground).show(ui.ctx(), |ui| { + egui::Frame::popup(ui.style()).inner_margin(2.0).show(ui, |ui| { + ui.set_min_width(width); + ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate); + ui.spacing_mut().item_spacing.y = 0.0; + let mut area = egui::ScrollArea::vertical().max_height(height).auto_shrink([false, true]); + if let Some(y) = reveal { + area = area.vertical_scroll_offset(y); + } + let out = area.show_rows(ui, row_h, list.matches.len(), |ui, rows| { + for row in rows { + let Some(text) = list.matches.get(row).and_then(|&i| list.items.get(i)) else { continue }; + if list_row(ui, width, row_h, egui::Button::selectable(row == list.index, text.as_str())).clicked() { + pick = Some(row); + } + } + }); + top = Some((out.state.clamped_offset().y / row_h).floor().max(0.0) as usize); + if more { + ui.add_space(2.0); + ui.weak(lang.tr(LIST_MORE_NOTE)); + } + }); + }); + if let Some(top) = top { + list.top = top; + } + if let Some(row) = pick { + list.index = row; + ed.list_accept = true; + app.commit_edit(0, 0, false, false); + } +} + /// Popup height for `n` items: every item up to `LIST_PICKER_MAX_ROWS`, then a scrollbar. pub(super) fn list_picker_height(n: usize, row_h: f32, gap: f32) -> f32 { let rows = n.clamp(1, LIST_PICKER_MAX_ROWS) as f32; @@ -117,45 +230,72 @@ pub(super) fn list_picker_height(n: usize, row_h: f32, gap: f32) -> f32 { /// Draws the validation list popup, choosing above/below and left/right placement for RTL, and applies the clicked item with `cell.set`. pub(super) fn list_picker(app: &mut SheetApp, ui: &mut egui::Ui, geo: &Geo, was_open: bool) { let Some(c) = app.grid.list_picker else { return }; + // An edit shows its own searched list; two lists would stack. + if app.editor.is_some() { + app.grid.list_picker = None; + app.grid.list_picker_items = None; + return; + } let Some(d) = app.session.active() else { return }; let wb = d.wb.clone(); let si = wb.active_sheet(); let Some(sh) = wb.sheet(si) else { return }; - let Some(dv) = sh.validations.iter().find(|x| x.ranges.iter().any(|r| r.contains(c))).cloned() else { + let Some(dv) = sh.validations.iter().find(|x| x.ranges.iter().any(|r| r.contains(c))) else { app.grid.list_picker = None; + app.grid.list_picker_items = None; return; }; - let items = gridcraft_engine::cmd::data::list_items(&wb, si, c, &dv); + // Read the list once while it stays open on the same cell of the same workbook version, and + // within the search budget, so a list over a huge column can't stall every frame. + // Taken out while the popup draws (a click runs a command on `app`), put back below. + let list = match app.grid.list_picker_items.take() { + Some(l) if Arc::ptr_eq(&l.wb, &wb) && l.sheet == si && l.cell == c => l, + _ => { + let budget = gridcraft_engine::cmd::data::LIST_SOURCE_BUDGET; + let source = gridcraft_engine::cmd::data::list_search_source(&wb, si, c, dv, budget); + super::ListPickerItems { wb: wb.clone(), sheet: si, cell: c, source } + } + }; + let (items, truncated) = (&list.source.items, list.source.truncated); let r = geo.cell_rect(sh, c); // Fit the popup to its rows (up to LIST_PICKER_MAX_ROWS); without a minimum the scroll area collapses to its 64 px default. - let height = list_picker_height(items.len(), LIST_PICKER_ROW_H, ui.spacing().item_spacing.y); + let gap = ui.spacing().item_spacing.y; + // A row is as tall as its button really is, so the popup shows LIST_PICKER_MAX_ROWS of them. + let row_h = list_row_height(ui); + let height = list_picker_height(items.len(), row_h, gap); + let note = if truncated { row_h + gap } else { 0.0 }; // Open below the cell, or above it when the rows would run past the bottom of the window (as Excel does). let screen = ui.ctx().content_rect(); - let above = r.bottom() + height + LIST_PICKER_CHROME > screen.bottom() && r.top() - height - LIST_PICKER_CHROME >= screen.top(); + let (outer, top_room) = (height + note + LIST_PICKER_CHROME, r.top() - height - note - LIST_PICKER_CHROME); + let above = r.bottom() + outer > screen.bottom() && top_room >= screen.top(); let (at, pivot) = match (above, geo.rtl) { (false, false) => (geo.mirror_pos(r.left_bottom()), Align2::LEFT_TOP), (false, true) => (geo.mirror_pos(r.left_bottom()), Align2::RIGHT_TOP), (true, false) => (geo.mirror_pos(r.left_top()), Align2::LEFT_BOTTOM), (true, true) => (geo.mirror_pos(r.left_top()), Align2::RIGHT_BOTTOM), }; + let lang = crate::i18n::current(ui.ctx()); let mut close = false; let response = egui::Area::new(egui::Id::unique("dv_list")).fixed_pos(at).pivot(pivot).order(egui::Order::Foreground).show(ui.ctx(), |ui| { egui::Frame::popup(ui.style()).inner_margin(2.0).show(ui, |ui| { ui.set_min_width(r.width().max(100.0)); - egui::ScrollArea::vertical().max_height(height).min_scrolled_height(height).show(ui, |ui| { - for it in &items { - if ui - .add(egui::Button::new(it.as_str()).frame_when_inactive(false).min_size(vec2(r.width().max(100.0), LIST_PICKER_ROW_H))) - .clicked() - { + // Only the rows in view are drawn: a long list costs what eight rows cost. + egui::ScrollArea::vertical().max_height(height).min_scrolled_height(height).show_rows(ui, row_h, items.len(), |ui, rows| { + for it in rows.filter_map(|i| items.get(i)) { + if list_row(ui, r.width().max(100.0), row_h, egui::Button::new(it.as_str()).frame_when_inactive(false)).clicked() { app.run_or_alert("cell.set", json!({"cell": c.a1(), "input": it})); close = true; } } }); + if truncated { + ui.weak(lang.tr(LIST_MORE_NOTE)); + } }); }); if close || popup_dismissed(&response.response, was_open) { app.grid.list_picker = None; + } else { + app.grid.list_picker_items = Some(list); } } diff --git a/crates/ui-egui/src/grid/show.rs b/crates/ui-egui/src/grid/show.rs index 97a1d9de6..713c2d51c 100644 --- a/crates/ui-egui/src/grid/show.rs +++ b/crates/ui-egui/src/grid/show.rs @@ -1,6 +1,6 @@ use super::Trace; use super::cursor::update_cursor; -use super::editor::{in_cell_editor, list_picker, validation_arrow}; +use super::editor::{in_cell_editor, list_picker, list_search, validation_arrow}; use super::geo::Geo; use super::interact::{interact, paint_freeze_handles}; use super::menus::{context_menu, error_check_tag, fill_menu, fill_options_tag, filter_menu, header_menu, object_menu}; @@ -379,6 +379,7 @@ fn show_grid_interactions(app: &mut SheetApp, ui: &mut egui::Ui, resp: &egui::Re if app.editor.as_ref().is_some_and(|e| !e.from_formula_bar) { in_cell_editor(app, ui, geo, sh, wb); } + list_search(app, ui, geo, sh); filter_menu(app, ui, geo, previous_popups.0 == app.grid.filter_menu); list_picker(app, ui, geo, previous_popups.1 == app.grid.list_picker); header_menu(app, ui, previous_popups.2 == app.grid.header_menu); diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 0e2677e88..cdc0ebd5f 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -509,6 +509,20 @@ mod tests { } } + /// The note under a validation list that was cut short is a sentence, not a feature name: a + /// catalog without it shows the English sentence in the middle of a translated interface. + #[test] + fn the_cut_short_list_note_is_translated_in_every_catalog() { + let key = crate::grid::editor::LIST_MORE_NOTE; + for language in Language::ALL { + let shown = language.tr(key); + assert!(!shown.contains('\n'), "{}: {key:?} is not a single line: {shown:?}", language.code()); + if language != Language::En { + assert_ne!(shown, key, "{} falls back to English for {key:?}", language.code()); + } + } + } + /// The Custom Sort dialog's own strings have a row in every catalog (no silent English /// fallback), keep the `{letters}` placeholder, and read as plain English in English. #[test] diff --git a/crates/ui-egui/src/i18n/cs.rs b/crates/ui-egui/src/i18n/cs.rs index 7fbf474c5..830039301 100644 --- a/crates/ui-egui/src/i18n/cs.rs +++ b/crates/ui-egui/src/i18n/cs.rs @@ -293,6 +293,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Naposledy použité", "No recent workbooks yet." => "Zatím žádné naposledy použité sešity.", "More workbooks" => "Další sešity", + "More entries not shown" => "Další položky nejsou zobrazeny", "Modified" => "Změněno", "Not available" => "Nedostupné", "Just now" => "Právě teď", diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index e1490bb96..0e2656609 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -310,6 +310,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Zuletzt verwendet", "No recent workbooks yet." => "Noch keine zuletzt verwendeten Arbeitsmappen.", "More workbooks" => "Weitere Arbeitsmappen", + "More entries not shown" => "Weitere Elemente werden nicht angezeigt", "Modified" => "Geändert", "Not available" => "Nicht verfügbar", "Just now" => "Gerade eben", diff --git a/crates/ui-egui/src/i18n/el.rs b/crates/ui-egui/src/i18n/el.rs index b5cab06d0..0cdc8c319 100644 --- a/crates/ui-egui/src/i18n/el.rs +++ b/crates/ui-egui/src/i18n/el.rs @@ -280,6 +280,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Πρόσφατα", "No recent workbooks yet." => "Δεν υπάρχουν ακόμη πρόσφατα βιβλία εργασίας.", "More workbooks" => "Περισσότερα βιβλία εργασίας", + "More entries not shown" => "Περισσότερα στοιχεία δεν εμφανίζονται", "Modified" => "Τροποποιήθηκε", "Not available" => "Μη διαθέσιμο", "Just now" => "Μόλις τώρα", diff --git a/crates/ui-egui/src/i18n/es.rs b/crates/ui-egui/src/i18n/es.rs index d318e998f..53d9852a3 100644 --- a/crates/ui-egui/src/i18n/es.rs +++ b/crates/ui-egui/src/i18n/es.rs @@ -299,6 +299,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Recientes", "No recent workbooks yet." => "Todavía no hay libros recientes.", "More workbooks" => "Más libros", + "More entries not shown" => "Hay más elementos que no se muestran", "Modified" => "Modificado", "Not available" => "No disponible", "Just now" => "Ahora mismo", diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index 1fdcb1279..1ebae6b31 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -386,6 +386,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Récent", "No recent workbooks yet." => "Aucun classeur récent pour le moment.", "More workbooks" => "Plus de classeurs", + "More entries not shown" => "D'autres éléments ne sont pas affichés", "Modified" => "Modifié", "Not available" => "Indisponible", "Just now" => "À l'instant", diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index 1154e1738..11a91de92 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -374,6 +374,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Recenti", "No recent workbooks yet." => "Nessuna cartella di lavoro recente.", "More workbooks" => "Altre cartelle di lavoro", + "More entries not shown" => "Altri elementi non visualizzati", "Modified" => "Modificato", "Not available" => "Non disponibile", "Just now" => "Adesso", diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index 3033b55e5..46b749e24 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -373,6 +373,7 @@ pub(super) const CORE: &[(&str, &str)] = &[ ("Recent", "最近使ったアイテム"), ("No recent workbooks yet.", "最近使ったブックはまだありません。"), ("More workbooks", "その他のブック"), + ("More entries not shown", "表示されていない項目があります"), ("Modified", "更新日時"), ("Not available", "利用できません"), ("Just now", "たった今"), diff --git a/crates/ui-egui/src/i18n/ko.rs b/crates/ui-egui/src/i18n/ko.rs index 2e5b7660f..1c702dc43 100644 --- a/crates/ui-egui/src/i18n/ko.rs +++ b/crates/ui-egui/src/i18n/ko.rs @@ -386,6 +386,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "최근 항목", "No recent workbooks yet." => "최근 통합 문서가 아직 없습니다.", "More workbooks" => "더 많은 통합 문서", + "More entries not shown" => "표시되지 않은 항목이 더 있습니다", "Modified" => "수정한 날짜", "Not available" => "사용할 수 없음", "Just now" => "방금", diff --git a/crates/ui-egui/src/i18n/nl.rs b/crates/ui-egui/src/i18n/nl.rs index 8267b65ef..ab4141bf5 100644 --- a/crates/ui-egui/src/i18n/nl.rs +++ b/crates/ui-egui/src/i18n/nl.rs @@ -373,6 +373,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Recent", "No recent workbooks yet." => "Nog geen recente werkmappen.", "More workbooks" => "Meer werkmappen", + "More entries not shown" => "Meer items worden niet weergegeven", "Modified" => "Gewijzigd", "Not available" => "Niet beschikbaar", "Just now" => "Zojuist", diff --git a/crates/ui-egui/src/i18n/pl.rs b/crates/ui-egui/src/i18n/pl.rs index 0b774cbf1..c3a8d7910 100644 --- a/crates/ui-egui/src/i18n/pl.rs +++ b/crates/ui-egui/src/i18n/pl.rs @@ -366,6 +366,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Ostatnie", "No recent workbooks yet." => "Nie masz jeszcze ostatnio używanych skoroszytów.", "More workbooks" => "Więcej skoroszytów", + "More entries not shown" => "Więcej elementów nie jest wyświetlanych", "Modified" => "Zmodyfikowano", "Not available" => "Niedostępne", "Just now" => "Przed chwilą", diff --git a/crates/ui-egui/src/i18n/pt.rs b/crates/ui-egui/src/i18n/pt.rs index a26216f1b..f5b63bb07 100644 --- a/crates/ui-egui/src/i18n/pt.rs +++ b/crates/ui-egui/src/i18n/pt.rs @@ -381,6 +381,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Recentes", "No recent workbooks yet." => "Ainda não há pastas de trabalho recentes.", "More workbooks" => "Mais pastas de trabalho", + "More entries not shown" => "Mais itens não exibidos", "Modified" => "Modificado", "Not available" => "Indisponível", "Just now" => "Agora mesmo", diff --git a/crates/ui-egui/src/i18n/ro.rs b/crates/ui-egui/src/i18n/ro.rs index e4b1ab3c7..4538099e2 100644 --- a/crates/ui-egui/src/i18n/ro.rs +++ b/crates/ui-egui/src/i18n/ro.rs @@ -373,6 +373,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Recente", "No recent workbooks yet." => "Încă niciun registru recent.", "More workbooks" => "Mai multe registre", + "More entries not shown" => "Alte elemente nu sunt afișate", "Modified" => "Modificat", "Not available" => "Indisponibil", "Just now" => "Chiar acum", diff --git a/crates/ui-egui/src/i18n/ru.rs b/crates/ui-egui/src/i18n/ru.rs index b08802fc3..198e00a3b 100644 --- a/crates/ui-egui/src/i18n/ru.rs +++ b/crates/ui-egui/src/i18n/ru.rs @@ -385,6 +385,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Последние", "No recent workbooks yet." => "Недавних книг пока нет.", "More workbooks" => "Другие книги", + "More entries not shown" => "Показаны не все элементы", "Modified" => "Изменён", "Not available" => "Недоступен", "Just now" => "Только что", diff --git a/crates/ui-egui/src/i18n/sr.rs b/crates/ui-egui/src/i18n/sr.rs index 5aabbf7b1..60f509e4b 100644 --- a/crates/ui-egui/src/i18n/sr.rs +++ b/crates/ui-egui/src/i18n/sr.rs @@ -379,6 +379,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Nedavno", "No recent workbooks yet." => "Još nema nedavnih radnih svezaka.", "More workbooks" => "Više radnih svezaka", + "More entries not shown" => "Još stavki nije prikazano", "Modified" => "Izmenjeno", "Not available" => "Nije dostupno", "Just now" => "Upravo sada", diff --git a/crates/ui-egui/src/i18n/tr.rs b/crates/ui-egui/src/i18n/tr.rs index ca59a0dd9..aff594a50 100644 --- a/crates/ui-egui/src/i18n/tr.rs +++ b/crates/ui-egui/src/i18n/tr.rs @@ -286,6 +286,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Son Kullanılanlar", "No recent workbooks yet." => "Henüz son kullanılan çalışma kitabı yok.", "More workbooks" => "Diğer çalışma kitapları", + "More entries not shown" => "Diğer öğeler gösterilmiyor", "Modified" => "Değiştirilme Tarihi", "Not available" => "Kullanılamıyor", "Just now" => "Az önce", diff --git a/crates/ui-egui/src/i18n/uk.rs b/crates/ui-egui/src/i18n/uk.rs index 33141bdff..0b2ef0121 100644 --- a/crates/ui-egui/src/i18n/uk.rs +++ b/crates/ui-egui/src/i18n/uk.rs @@ -370,6 +370,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Останні", "No recent workbooks yet." => "Нещодавніх книг поки немає.", "More workbooks" => "Інші книги", + "More entries not shown" => "Показано не всі елементи", "Modified" => "Змінено", "Not available" => "Недоступно", "Just now" => "Щойно", diff --git a/crates/ui-egui/src/i18n/vi.rs b/crates/ui-egui/src/i18n/vi.rs index 100230d02..340ccd214 100644 --- a/crates/ui-egui/src/i18n/vi.rs +++ b/crates/ui-egui/src/i18n/vi.rs @@ -376,6 +376,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "Gần đây", "No recent workbooks yet." => "Chưa có sổ làm việc gần đây.", "More workbooks" => "Sổ làm việc khác", + "More entries not shown" => "Còn mục khác chưa được hiển thị", "Modified" => "Đã sửa đổi", "Not available" => "Không khả dụng", "Just now" => "Vừa xong", diff --git a/crates/ui-egui/src/i18n/zh.rs b/crates/ui-egui/src/i18n/zh.rs index 36e1d4cca..66172ab50 100644 --- a/crates/ui-egui/src/i18n/zh.rs +++ b/crates/ui-egui/src/i18n/zh.rs @@ -384,6 +384,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Recent" => "最近", "No recent workbooks yet." => "还没有最近使用的工作簿。", "More workbooks" => "更多工作簿", + "More entries not shown" => "还有更多项未显示", "Modified" => "修改时间", "Not available" => "不可用", "Just now" => "刚刚", diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index 83f4b5736..bb69e2e56 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -126,6 +126,7 @@ mod ui_clock; mod undo_while_grouping; mod validation_alert; mod validation_input_message; +mod validation_list_search; mod wheel_zoom; mod whole_line_shortcuts; mod widgets; diff --git a/crates/ui-egui/tests/it/validation_list_search.rs b/crates/ui-egui/tests/it/validation_list_search.rs new file mode 100644 index 000000000..fc7b2ec81 --- /dev/null +++ b/crates/ui-egui/tests/it/validation_list_search.rs @@ -0,0 +1,367 @@ +//! Typing into a cell with a list validation searches its dropdown: the list shows the entries +//! with a word starting with the typed text, and Enter or Tab takes the highlighted one. + +use egui::{Event, Key, Modifiers, PointerButton}; +use egui_kittest::kittest::Queryable; +use gridcraft_engine::Session; +use gridcraft_engine::core::{CellRef, Value}; +use gridcraft_ui_egui::grid; +use serde_json::json; + +use crate::common::{self, Harness}; + +/// A 1200×800 harness on the pinned test font set: row heights must not depend on the fonts the +/// host happens to have installed. +fn open(session: Session) -> Harness { + common::harness_with(common::builder().with_size(egui::vec2(1200.0, 800.0)), common::app(session), 4) +} + +const CITIES: [&str; 6] = [ + "Paris - France", + "Dubai - United Arab Emirates", + "London - United Kingdom", + "Boston - United States of America", + "Los Angeles - United States of America", + "Bogotá - Colombia", +]; + +fn harness_with(rule: serde_json::Value) -> Harness { + let mut session = Session::new(); + session.new_workbook(); + let rows: Vec> = CITIES.iter().map(|c| vec![*c]).collect(); + session.execute("range.setValues", json!({"range": "H1", "values": rows})).unwrap(); + session.execute("data.validation", rule).unwrap(); + session.execute("selection.set", json!({"cell": "B2"})).unwrap(); + open(session) +} + +fn harness() -> Harness { + harness_with(json!({"range": "B2:B9", "type": "list", "formula1": "=$H$1:$H$6"})) +} + +fn key(h: &mut Harness, k: Key, m: Modifiers) { + h.input_mut().events.push(Event::Key { key: k, physical_key: None, pressed: true, repeat: false, modifiers: m }); + h.input_mut().events.push(Event::Key { key: k, physical_key: None, pressed: false, repeat: false, modifiers: m }); + h.run_steps(2); +} + +fn text(h: &mut Harness, t: &str) { + h.input_mut().events.push(Event::Text(t.into())); + h.run_steps(2); +} + +fn value(h: &Harness, a: &str) -> String { + match h.state().session.active().and_then(|d| d.wb.active().map(|s| s.value(CellRef::parse(a).unwrap_or_default()))) { + Some(Value::Text(t)) => t.to_string(), + Some(v) => v.display(), + None => String::new(), + } +} + +fn active(h: &Harness) -> String { + h.state().session.active().map(|d| d.selection.active.a1()).unwrap_or_default() +} + +fn shown(h: &Harness, item: &str) -> bool { + h.query_by_label(item).is_some() +} + +#[test] +fn typing_filters_the_list_to_entries_with_a_matching_word() { + let mut h = harness(); + text(&mut h, "United"); + assert!(h.state().editor.as_ref().is_some_and(|e| e.list_open()), "typing opens the searched list"); + for city in &CITIES[1..5] { + assert!(shown(&h, city), "{city} matches 'United'"); + } + assert!(!shown(&h, "Paris - France")); + text(&mut h, " St"); + assert!(shown(&h, "Boston - United States of America")); + assert!(shown(&h, "Los Angeles - United States of America")); + assert!(!shown(&h, "London - United Kingdom"), "'United St' narrows to the United States"); + if let Ok(path) = std::env::var("GRIDCRAFT_LIST_SEARCH_SCREENSHOT") { + key(&mut h, Key::ArrowDown, Modifiers::NONE); + h.render().unwrap().save(path).unwrap(); + } +} + +#[test] +fn enter_commits_the_first_match_as_the_list_spells_it() { + let mut h = harness(); + text(&mut h, "united st"); + key(&mut h, Key::Enter, Modifiers::NONE); + assert!(h.state().editor.is_none()); + assert!(h.state().message.is_none(), "no validation alert: the value is a list entry"); + assert_eq!(value(&h, "B2"), "Boston - United States of America"); + assert_eq!(active(&h), "B3"); +} + +#[test] +fn tab_commits_and_moves_right() { + let mut h = harness(); + text(&mut h, "Ange"); + key(&mut h, Key::Tab, Modifiers::NONE); + assert_eq!(value(&h, "B2"), "Los Angeles - United States of America"); + assert_eq!(active(&h), "C2"); +} + +#[test] +fn arrows_move_the_highlight_instead_of_committing() { + let mut h = harness(); + text(&mut h, "United"); + key(&mut h, Key::ArrowDown, Modifiers::NONE); + key(&mut h, Key::ArrowDown, Modifiers::NONE); + assert!(h.state().editor.is_some(), "Down moves in the list, it doesn't commit"); + key(&mut h, Key::ArrowUp, Modifiers::NONE); + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(value(&h, "B2"), "London - United Kingdom"); +} + +#[test] +fn accents_and_case_are_ignored() { + let mut h = harness(); + text(&mut h, "BOGOTA"); + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(value(&h, "B2"), "Bogotá - Colombia"); +} + +#[test] +fn clicking_an_entry_commits_it() { + let mut h = harness(); + text(&mut h, "United"); + h.get_by_label("London - United Kingdom").click(); + h.run_steps(3); + assert!(h.state().editor.is_none()); + assert_eq!(value(&h, "B2"), "London - United Kingdom"); + assert_eq!(active(&h), "B2"); +} + +#[test] +fn escape_closes_the_list_then_cancels() { + let mut h = harness_with(json!({"range": "B2", "type": "list", "formula1": "=$H$1:$H$6", "errorStyle": "information"})); + text(&mut h, "United"); + key(&mut h, Key::Escape, Modifiers::NONE); + assert!(h.state().editor.as_ref().is_some_and(|e| !e.list_open() && e.text == "United"), "the first Escape only hides the list"); + // With the list closed, Enter keeps the typed text (an Information rule accepts it). + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(value(&h, "B2"), "United"); + + let mut h = harness(); + text(&mut h, "United"); + key(&mut h, Key::Escape, Modifiers::NONE); + key(&mut h, Key::Escape, Modifiers::NONE); + assert!(h.state().editor.is_none(), "the second Escape cancels the edit"); + assert_eq!(value(&h, "B2"), ""); +} + +#[test] +fn no_match_leaves_the_typed_text_to_validation() { + let mut h = harness(); + text(&mut h, "Tokyo"); + assert!(h.state().editor.as_ref().is_some_and(|e| !e.list_open())); + key(&mut h, Key::Enter, Modifiers::NONE); + assert!(h.state().message.is_some(), "a Stop rule rejects a value outside the list"); + assert_eq!(value(&h, "B2"), ""); +} + +#[test] +fn formulas_are_not_searched() { + let mut h = harness(); + text(&mut h, "=H1"); + assert!(h.state().editor.as_ref().is_some_and(|e| !e.list_open())); +} + +#[test] +fn a_long_list_shows_a_few_rows_and_scrolls_to_the_highlight() { + let mut session = Session::new(); + session.new_workbook(); + let rows: Vec> = (0..50_000).map(|i| vec![format!("Item {i:05}")]).collect(); + session.execute("range.setValues", json!({"range": "H1", "values": rows})).unwrap(); + session.execute("data.validation", json!({"range": "B2", "type": "list", "formula1": "=$H$1:$H$50000"})).unwrap(); + session.execute("selection.set", json!({"cell": "B2"})).unwrap(); + let mut h = open(session); + text(&mut h, "item"); + assert!(shown(&h, "Item 00000")); + assert!(!shown(&h, "Item 00100"), "only the visible rows are drawn"); + for _ in 0..12 { + key(&mut h, Key::ArrowDown, Modifiers::NONE); + } + assert!(shown(&h, "Item 00012"), "the highlighted row scrolls into view"); + assert!(!shown(&h, "Item 00000")); + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(value(&h, "B2"), "Item 00012"); +} + +#[test] +fn typing_over_the_open_dropdown_replaces_it_with_the_searched_list() { + let mut h = harness(); + let app = h.state(); + let sh = app.session.active().unwrap().wb.active().unwrap(); + let geo = grid::Geo::new(sh, app.grid.rect.unwrap(), app.view().scroll); + let pos = grid::validation_arrow(sh, &geo, CellRef::parse("B2").unwrap()).unwrap().center(); + h.input_mut().events.push(Event::PointerMoved(pos)); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + assert!(h.state().grid.list_picker.is_some(), "the arrow opens the full list"); + assert!(shown(&h, "Paris - France")); + + text(&mut h, "United St"); + assert!(h.state().grid.list_picker.is_none(), "typing closes the full list"); + assert!(h.state().grid.list_picker_items.is_none(), "and drops the entries it read"); + assert!(!shown(&h, "Paris - France"), "only the searched list shows"); + assert_eq!(h.query_all_by_label("Boston - United States of America").count(), 1, "one list, not two"); + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(value(&h, "B2"), "Boston - United States of America"); + assert!(h.state().grid.list_picker.is_none()); + assert!(!shown(&h, "Boston - United States of America"), "no list is left open after choosing"); +} + +fn click_cell(h: &mut Harness, cell: &str) { + let app = h.state(); + let sh = app.session.active().unwrap().wb.active().unwrap(); + let geo = grid::Geo::new(sh, app.grid.rect.unwrap(), app.view().scroll); + let pos = geo.cell_rect(sh, CellRef::parse(cell).unwrap()).center(); + h.input_mut().events.push(Event::PointerMoved(pos)); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); +} + +#[test] +fn leaving_the_cell_without_accepting_keeps_the_typed_text() { + // An Information rule lets the typed text in, so the commit itself succeeds. + let mut h = harness_with(json!({"range": "B2", "type": "list", "formula1": "=$H$1:$H$6", "errorStyle": "information"})); + text(&mut h, "United"); + assert!(h.state().editor.as_ref().is_some_and(|e| e.list_open())); + click_cell(&mut h, "E2"); // beside the cell: the popup hangs below it + assert!(h.state().editor.is_none(), "clicking another cell commits the edit"); + assert_eq!(value(&h, "B2"), "United", "only Enter, Tab or a click on the list takes its entry"); + + // Ctrl+Enter is an Enter: it takes the highlighted entry. + let mut h = harness(); + text(&mut h, "Ange"); + key(&mut h, Key::Enter, Modifiers::COMMAND); + assert_eq!(value(&h, "B2"), "Los Angeles - United States of America"); +} + +#[test] +fn the_formula_bar_enter_button_takes_the_highlighted_entry() { + let mut h = harness(); + text(&mut h, "united st"); + // The ✓ button sits right of the Name Box (118 wide), after the ✕ button: both are 22 wide + // with 4-point gaps. The Name Box is the leftmost text field; its text starts 6 points in. + let name_box = h.get_all_by_role(egui::accesskit::Role::TextInput).map(|n| n.rect()).min_by(|a, b| a.left().total_cmp(&b.left())).unwrap(); + let pos = egui::pos2(name_box.left() - 6.0 + 118.0 + 4.0 + 4.0 + 4.0 + 22.0 + 4.0 + 11.0, name_box.center().y); + h.input_mut().events.push(Event::PointerMoved(pos)); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(3); + assert!(h.state().editor.is_none(), "the Enter button commits"); + assert!(h.state().message.is_none(), "no validation alert: the list entry was taken"); + assert_eq!(value(&h, "B2"), "Boston - United States of America"); + assert_eq!(active(&h), "B2", "the Enter button doesn't move the selection"); +} + +#[test] +fn a_list_from_a_huge_column_is_read_within_the_source_budget() { + // Typing into a cell whose list is a whole column used far past the budget reads only the + // budget's worth of it, and the edit knows the list was cut short. + let budget = gridcraft_engine::cmd::data::LIST_SOURCE_BUDGET; + let rows: Vec> = (0..budget + 1_000).map(|r| vec![format!("Item {r}")]).collect(); + let mut session = Session::new(); + session.new_workbook(); + session.execute("range.setValues", json!({"range": "H1", "values": rows})).unwrap(); + session.execute("data.validation", json!({"range": "B2", "type": "list", "formula1": "=$H:$H"})).unwrap(); + session.execute("selection.set", json!({"cell": "B2"})).unwrap(); + let mut h = open(session); + text(&mut h, "zzz"); + let list = h.state().editor.as_ref().and_then(|e| e.list.as_ref()).map(|l| (l.items.len(), l.truncated, l.matches.len())); + assert_eq!(list, Some((budget, true, 0))); +} + +#[test] +fn the_dropdown_arrow_reads_a_huge_list_once_and_draws_only_its_visible_rows() { + // The full list the arrow opens comes from a whole column used far past the search budget: it + // is read once within the budget (not again every frame) and only the rows in view are drawn. + let budget = gridcraft_engine::cmd::data::LIST_SOURCE_BUDGET; + let rows: Vec> = (0..budget + 1_000).map(|r| vec![format!("Item {r}")]).collect(); + let mut session = Session::new(); + session.new_workbook(); + session.execute("range.setValues", json!({"range": "H1", "values": rows})).unwrap(); + session.execute("data.validation", json!({"range": "B2", "type": "list", "formula1": "=$H:$H"})).unwrap(); + session.execute("selection.set", json!({"cell": "B2"})).unwrap(); + let mut h = open(session); + key(&mut h, Key::ArrowDown, Modifiers::ALT); + assert!(h.state().grid.list_picker.is_some(), "Alt+Down opens the full list"); + let read = |h: &Harness| h.state().grid.list_picker_items.as_ref().map(|l| (l.source.items.len(), l.source.truncated, l.source.items.as_ptr())); + let first = read(&h); + assert_eq!(first.map(|(n, t, _)| (n, t)), Some((budget, true))); + h.run_steps(3); + assert_eq!(read(&h), first, "the open list is not read again"); + assert!(shown(&h, "Item 0")); + assert!(!shown(&h, "Item 500"), "rows out of view are not drawn"); + assert!(shown(&h, "More entries not shown")); + key(&mut h, Key::Escape, Modifiers::NONE); + assert!(h.state().grid.list_picker.is_none()); + assert!(h.state().grid.list_picker_items.is_none(), "closing drops the list"); +} + +#[test] +fn the_highlighted_row_stays_inside_the_popup() { + // 50,000 entries match "item": the list is cut at the match cap, so the note sits right under + // the rows. A highlighted row drawn below the note's top is outside the popup's visible rows + // (rows used to be laid out 18 px apart while drawn 24 px tall). + let mut session = Session::new(); + session.new_workbook(); + let rows: Vec> = (0..50_000).map(|i| vec![format!("Item {i:05}")]).collect(); + session.execute("range.setValues", json!({"range": "H1", "values": rows})).unwrap(); + session.execute("data.validation", json!({"range": "B2", "type": "list", "formula1": "=$H$1:$H$50000"})).unwrap(); + session.execute("selection.set", json!({"cell": "B2"})).unwrap(); + let mut h = open(session); + text(&mut h, "item"); + let inside = |h: &Harness, item: &str| { + let row = h.get_by_label(item).rect(); + let note = h.get_by_label("More entries not shown").rect(); + assert!(row.bottom() <= note.top() + 0.5, "{item} at {row:?} runs under the note at {note:?}"); + }; + let visible = gridcraft_ui_egui::editor::ListSearch::VISIBLE; + for _ in 1..visible { + key(&mut h, Key::ArrowDown, Modifiers::NONE); + } + // The last row that fits without scrolling. + inside(&h, &format!("Item {:05}", visible - 1)); + assert!(shown(&h, "Item 00000"), "the list did not need to scroll yet"); + // Up from the first entry wraps to the last kept match: the end of the list is reachable. + for _ in 1..visible { + key(&mut h, Key::ArrowUp, Modifiers::NONE); + } + key(&mut h, Key::ArrowUp, Modifiers::NONE); + let last = format!("Item {:05}", gridcraft_engine::cmd::data::LIST_MATCH_CAP - 1); + inside(&h, &last); + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(value(&h, "B2"), last); +} + +#[test] +fn the_searched_list_opens_above_a_cell_near_the_bottom_of_the_window() { + let mut h = harness_with(json!({"range": "B2:B200", "type": "list", "formula1": "=$H$1:$H$6"})); + // The last row of column B that is wholly in view. + let (cell, top) = { + let app = h.state(); + let sh = app.session.active().unwrap().wb.active().unwrap(); + let rect = app.grid.rect.unwrap(); + let geo = grid::Geo::new(sh, rect, app.view().scroll); + let row = (1..200).take_while(|&r| geo.cell_rect(sh, CellRef::new(r, 1)).bottom() <= rect.bottom()).last().unwrap(); + let cell = CellRef::new(row, 1); + (cell, geo.cell_rect(sh, cell).top()) + }; + h.state_mut().session.execute("selection.set", json!({"cell": cell.a1()})).unwrap(); + h.run_steps(2); + text(&mut h, "united"); + let row = h.get_by_label("Boston - United States of America").rect(); + assert!(row.bottom() <= top + 0.5, "the list at {row:?} is above the cell (top {top})"); + assert!(row.top() >= 0.0); + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(value(&h, &cell.a1()), "Dubai - United Arab Emirates"); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index c83f8d82b..a614fb165 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-11-05 · **Change:** minor (Find and Replace keeps workbook Undo/Redo available while a button has keyboard focus; text fields keep their own Undo; earlier: punctuation shortcuts follow the keyboard layout's characters; earlier: preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-15 · **Change:** minor (validation list rows keep to their slot height whatever the font, and the "More entries not shown" note is translated; earlier: the searched validation list shows its eight rows, keeps the highlight in view and opens above a cell near the bottom of the window; earlier: the dropdown arrow's full list reads its source once within the same budget, draws only its visible rows and shows eight of them; earlier: a searched validation list reads at most 200,000 cells of its source; earlier: Find and Replace keeps workbook Undo/Redo available while a button has keyboard focus; text fields keep their own Undo; earlier: punctuation shortcuts follow the keyboard layout's characters; earlier: preserve centered emoji and symbol fallback placement; earlier: preserve leading and trailing blank cell lines; earlier: align wrapped and unwrapped cells; earlier: CJK title baseline regression and mixed-script rendering validation; earlier: form controls: buttons, sliders and spin buttons on the sheet; earlier: Highlight the active cell's row, a global preference in File › Options › General; earlier: a linked cell's menu edits, opens or removes the link; earlier: Display options for this workbook: sheet tabs and scroll bars; earlier: dragging over row or column headers in point mode extends the reference; earlier: a picture on the system clipboard pastes as a floating picture at the active cell with Cmd/Ctrl+V or Paste (#699); earlier: frozen columns keep their text, gridlines and merged borders whole while the sheet scrolls (#2544); earlier: every Paste Special option has its access key; earlier: the Draw tab's live stroke preview uses the pen's colour and thickness; earlier: copy quotes only cells with a tab or line break, as Excel does; earlier: Ctrl+. Next Corner of Selection; earlier: dragging the selection's border onto data asks before replacing it; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis use them, the arrow keys select while a dialog is collapsed and F4 cycles a reference's anchors; earlier: Python cells: Python mode in the formula bar; earlier: Insert › Equation and the equation editor; earlier: every floating object selects, resizes from eight handles and deletes with the keyboard; earlier: Formulas › Error Checking › Trace Error; trace arrows stay through a zoom (#3097); earlier: Page Setup sets the page order, Down, then over or Over, then down, which printing, the print preview, Page Break Preview and Page Layout view follow; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and the Insert Function categories; Esc leaves a File-page text field before closing the view; earlier: checkbox cells print as boxes; Ctrl+arrow and Ctrl+Shift+arrow while pointing a formula reference; editing a hyperlink loads its existing fields; AutoSum over a selected row puts its total to the right; ribbon catalog count 276 / 292; earlier: typing into a cell with a list validation searches its dropdown; Enter/Tab take the highlighted entry) · **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 @@ -64,6 +64,7 @@ this logic, with one undo step. | Number-format colors (`[Green]`, `[Color1]`–`[Color56]`) | Rendered in grid and PDF from shared RGB mappings (#1452) | | Point mode (click/drag/arrow references), reference colouring, F4 | done | | AutoComplete in columns, function autocomplete and argument tips | done; cell helpers clip to the worksheet and hide when the editor scrolls out (#200) | +| Searchable data validation dropdown (typing filters the in-cell list) | done (10-21): entries with a word starting with the typed text, ignoring case and the accents of Latin letters (é, ç, ß, ł, ș, ǎ, Vietnamese ộ: Latin-1, Latin Extended-A and -B, Latin Extended Additional; other scripts keep their marks), in list order; Up/Down highlight, Enter/Tab/Ctrl+Enter/click commit the highlighted entry as the list spells it (other commits, such as clicking another cell, keep the typed text), Escape hides the list then cancels; `data.validationList {cell, search?}` gives agents the same search. The search reads at most 200,000 cells of the list's source and keeps at most 10,000 matches; past either, `truncated` is set and the popup says more entries aren't shown (validation itself still checks the whole list). Fuzzy matching isn't offered (Excel doesn't either); behaviour follows the documented Excel 365 feature, not yet measured against the app | | Header resize and double-click AutoFit | done (#42, #88 for header dividers) | | Data › Advanced Filter | dialog offers in-place or copy-to filtering, list and optional criteria ranges, and unique records; Alt+A,Q opens it (#1622). The engine's copy-to path clears only the result footprint and rejects worksheet overflow (#1031). | | 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; Data › Outline › Settings (`data.outlineSettings`) puts summary rows above and summary columns left of their detail, saved as `outlinePr` (the dialog's Automatic styles check box and Apply Styles button are missing), View › Show Outline Symbols (Ctrl+8) hides the bands and is saved with the sheet, and a block of cells still groups rows without the Rows / Columns dialog | @@ -270,6 +271,10 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12. | Date | Change | Summary | |---|---|---| +| 2026-11-15 | minor | The rows of both validation list popups are drawn in slots of exactly the row height the popup scrolls by, so a font whose text is laid out a pixel taller than its nominal line height no longer pushes the last visible row under the "More entries not shown" note (seen with the pinned test fonts, not with the fonts of a desktop install). That note is translated in all 18 interface catalogs, and the validation-list UI tests run on the pinned font set | +| 2026-11-14 | minor | The searched validation list measures its rows at their real height, like the dropdown arrow's list: it shows eight rows instead of six, the highlighted row stays in view and the last entries of a long list can be reached. It opens above the cell when it would run past the bottom of the window, measures its width once per search instead of every frame, and its "More entries not shown" note goes through the interface translations. Typing over the open dropdown drops the entries the dropdown had read | +| 2026-11-13 | minor | The full list the dropdown arrow (or Alt+Down) opens reads its source once while it stays open, within the same 200,000-cell budget, and draws only the rows in view, so a list over a huge column no longer rereads and redraws every entry each frame; it says when entries aren't shown, and its rows are measured at their real height so eight show, as intended | +| 2026-11-13 | minor | A searched validation list reads at most 200,000 cells of its source (`LIST_SOURCE_BUDGET`), walking a range source within the used range instead of evaluating it whole, so a list over a huge or whole column can't stall the edit; `data.validationList` reports `truncated` and the popup says when entries aren't shown | | 2026-11-05 | minor | Reconcile upstream form-control coverage with the CJK baseline and cell-alignment updates | | 2026-11-04 | minor | Keep centered emoji and symbol fallback placement when a row starts with a fallback or contains only fallbacks; use primary or baseline-aligned glyphs to anchor cell alignment | | 2026-11-04 | minor | Preserve leading and trailing blank lines in wrapped cells when calculating vertical alignment; regression covers single, multiple and all-empty lines | @@ -329,6 +334,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12. | 2026-10-22 | minor | One native window per workbook window on the desktop: per-window drafts, dialogs and ribbons; menu bar commands go to the focused window; closing one of several windows on a workbook doesn't ask; Quit asks in each unsaved workbook's window; the last window closed quits (Windows, Linux) or leaves macOS running | | 2026-10-22 | minor | New Window opens a second window on the same workbook instead of a copy that saved over the original; windows keep their own selection, sheet and scroll; titles Name:1 / Name:2; Switch Windows, Hide and Unhide work by window; File › Close closes one window of several without asking | | 2026-10-22 | minor | New workbook no longer loses the first one: the cell being typed is entered into its own workbook before any File or window command (an entry the workbook refuses stays open and the command doesn't run; an untouched F2 draft changes nothing), the editor is tied to its workbook, View › Switch Windows and the macOS Window menu list the open workbooks, and the macOS Quit item asks about unsaved workbooks like the close button | +| 2026-10-21 | minor | Typing into a cell with an in-cell list validation shows the list filtered to entries with a word starting with the typed text (case and Latin accents ignored, Vietnamese included, list order kept, only visible rows drawn); Up/Down move the highlight, Enter/Tab/click commit it with the list's spelling, Escape hides the list before cancelling. Column AutoComplete is off for those cells. New query command `data.validationList` | | 2026-10-21 | minor | Background error checking, first part (#1994): a constant whose text would be a number if typed (signs, thousands, currency, percent, exponent, parenthesised negative) gets Excel's green corner triangle; the active cell then shows a warning button whose menu names the problem and offers Convert to Number for the selection (`formulas.convertToNumber`). Dates, times and fractions kept as text and formula results are not flagged, as in Excel | | 2026-10-21 | minor | Paste Special laid out as Excel's: Paste and Operation options each in two columns inside a frame, Skip blanks and Transpose side by side, Paste Link as a button that pastes references at once; labels translated (the generic form didn't translate them) and the window no longer runs past the screen | | 2026-10-21 | minor | Form dialogs (conditional-format quick rules, New Name, Remove Duplicates, Text to Columns and every other `Dialog::form`) fit their content: OK and Cancel sit in a row under the last field instead of a right-to-left layout that took the screen's whole height and left the buttons floating halfway down |