mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-24 10:46:50 -06:00
#1528: a formula's references are outlined only on the sheet they belong to
While pointing at another sheet, a reference without a sheet name (A1) was outlined on the sheet being shown instead of the sheet the edit started on. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
c30fa3f1cf
commit
beade8b734
@@ -238,6 +238,13 @@ pub fn formula_refs(text: &str) -> Vec<(usize, usize, RangeRef, Option<String>,
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether a reference of the formula being edited belongs on the sheet shown: a reference with a
|
||||
/// sheet name is on that sheet, one without is on the sheet the edit started on, even while
|
||||
/// pointing at another sheet.
|
||||
pub fn ref_is_on_sheet(ref_sheet: Option<&str>, origin: &str, shown: &str) -> bool {
|
||||
ref_sheet.unwrap_or(origin).eq_ignore_ascii_case(shown)
|
||||
}
|
||||
|
||||
/// Excel-style AutoComplete: the one distinct text entry in the same column (contiguous data
|
||||
/// above and below) that starts with `typed` (case-insensitive). `None` when ambiguous.
|
||||
pub fn column_completion(sheet: &gridcraft_engine::model::Sheet, at: CellRef, typed: &str) -> Option<String> {
|
||||
@@ -329,4 +336,14 @@ mod tests {
|
||||
assert_eq!(r[1].2.a1(), "B2:C3");
|
||||
assert_eq!(r[3].3.as_deref(), Some("Sheet2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refs_are_outlined_on_their_own_sheet_only() {
|
||||
// Pointing at Sheet2 while the edit started on Sheet1: `A1` stays on Sheet1, `Sheet2!B2` shows on Sheet2.
|
||||
assert!(ref_is_on_sheet(None, "Sheet1", "Sheet1"));
|
||||
assert!(!ref_is_on_sheet(None, "Sheet1", "Sheet2"));
|
||||
assert!(ref_is_on_sheet(Some("Sheet2"), "Sheet1", "Sheet2"));
|
||||
assert!(!ref_is_on_sheet(Some("Sheet2"), "Sheet1", "Sheet1"));
|
||||
assert!(ref_is_on_sheet(Some("sheet2"), "Sheet1", "Sheet2"), "sheet names compare ignoring case");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1623,8 +1623,9 @@ pub(crate) fn paint_selection(
|
||||
if let Some(ed) = &app.editor
|
||||
&& ed.is_formula()
|
||||
{
|
||||
let origin = app.session.active().and_then(|d| d.wb.sheet(ed.sheet)).map_or(sh.name.as_str(), |o| o.name.as_str());
|
||||
for (_, _, r, sheet, idx) in crate::editor::formula_refs(&ed.text) {
|
||||
if sheet.as_deref().is_some_and(|s| !s.eq_ignore_ascii_case(&sh.name)) {
|
||||
if !crate::editor::ref_is_on_sheet(sheet.as_deref(), origin, &sh.name) {
|
||||
continue;
|
||||
}
|
||||
if !range_in_pane(r, rows, cols) {
|
||||
|
||||
Reference in New Issue
Block a user