Merge storytold/gridcraft#2510: Status bar: Circular References names a cell only when a loop is on the active sheet

This commit is contained in:
aiongg
2026-10-25 02:24:49 +00:00
2 changed files with 36 additions and 3 deletions
+8 -3
View File
@@ -281,9 +281,14 @@ pub fn status_bar(app: &mut SheetApp, ui: &mut Ui) {
}
if !d.calc.circular.is_empty() {
ui.add_space(12.0);
let (si, c) = d.calc.circular[0];
let name = d.wb.sheet(si).map(|s| gridcraft_engine::formula::quote_sheet(&s.name)).unwrap_or_default();
ui.label(egui::RichText::new(format!("Circular References: {name}!{}", c.a1())).font(theme::ui_font(12.5)).color(t.danger));
let label = match d.calc.circular.iter().find(|(si, _)| *si == d.wb.active_sheet) {
Some(&(si, c)) => {
let name = d.wb.sheet(si).map(|s| gridcraft_engine::formula::quote_sheet(&s.name)).unwrap_or_default();
format!("Circular References: {name}!{}", c.a1())
}
None => "Circular References".to_owned(),
};
ui.label(egui::RichText::new(label).font(theme::ui_font(12.5)).color(t.danger));
}
if app.session.clipboard.is_some() && app.editor.is_none() {
ui.add_space(12.0);
+28
View File
@@ -931,6 +931,34 @@ fn status_bar_quotes_the_sheet_name_of_a_circular_reference() {
assert!(h.query_by_label("Circular References: 'Bob''s Q1'!B2").is_some(), "the status bar names the cell as a reference");
}
#[test]
fn status_bar_names_no_cell_when_every_circular_reference_is_on_another_sheet() {
let mut s = blank();
s.execute("home.insertSheet", json!({"name": "Data"})).unwrap();
s.execute("cell.set", json!({"cell": "B2", "input": "=B2+1"})).unwrap();
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
let mut h = harness(s);
assert!(h.query_by_label("Circular References").is_some(), "the status bar still reports circular references");
assert!(h.query_by_label("Circular References: Data!B2").is_none(), "no cell address from another sheet");
h.state_mut().session.execute("sheet.activate", json!({"sheet": "Data"})).unwrap();
h.run_steps(2);
assert!(h.query_by_label("Circular References: Data!B2").is_some(), "the active sheet's loop is named");
}
#[test]
fn status_bar_names_a_circular_reference_on_the_active_sheet() {
let mut s = blank();
s.execute("cell.set", json!({"cell": "A1", "input": "=A1+1"})).unwrap();
s.execute("home.insertSheet", json!({"name": "Data"})).unwrap();
s.execute("cell.set", json!({"cell": "B2", "input": "=B2+1"})).unwrap();
s.execute("formulas.calculateNow", json!({})).unwrap();
let circular = s.active().unwrap().calc.circular.clone();
assert_eq!(circular, vec![(0, CellRef::new(0, 0)), (1, CellRef::new(1, 1))], "Sheet1's loop is listed first");
let h = harness(s);
assert!(h.query_by_label("Circular References: Data!B2").is_some(), "the status bar names the loop on the active sheet");
assert!(h.query_by_label("Circular References: Sheet1!A1").is_none(), "not the first loop listed");
}
#[test]
fn alt_f8_opens_the_macros_dialog() {
let mut h = harness(blank());