Merge pull request #683 from marcoarnulfo:fix/select-inserted-chart

This commit is contained in:
Brandon Thomas 2026-10-12 23:48:45 -04:00
commit decc64a59b
2 changed files with 26 additions and 0 deletions

View File

@ -378,6 +378,13 @@ impl SheetApp {
}
let r = self.session.run(id, params);
self.after_engine();
// The new chart is selected, as after inserting any object, so Delete removes it, not its data.
if id == "insert.chart"
&& let Ok(r) = &r
&& let Some(chart) = r.get("chart").and_then(Json::as_u64).and_then(|id| u32::try_from(id).ok())
{
self.selected_chart = Some(chart);
}
if id == "file.exportPdf"
&& let Ok(r) = &r
{

View File

@ -224,6 +224,25 @@ fn delete_key_removes_the_selected_chart() {
assert_eq!(value(&h, "A1"), Value::Number(1.0));
}
#[test]
fn inserted_chart_is_selected_so_delete_removes_it() {
// #668, #256: after Insert › Chart the selection stayed on the source cells, so Delete
// cleared the data and left the chart behind.
let mut session = blank();
session.execute("range.setValues", json!({"range": "A1:B2", "values": [[1, 2], [3, 4]]})).unwrap();
session.execute("selection.set", json!({"range": "A1:B2"})).unwrap();
let mut h = harness(session);
let id = h.state_mut().run("insert.chart", json!({"type": "column"})).unwrap()["chart"].as_u64().unwrap() as u32;
h.run_steps(2);
assert_eq!(h.state().selected_chart, Some(id), "the new chart is selected");
key(&mut h, Key::Delete, Modifiers::NONE);
assert!(h.state().session.active().unwrap().wb.active().unwrap().charts.is_empty());
assert_eq!(value(&h, "A1"), Value::Number(1.0));
}
#[test]
fn renders_every_ribbon_tab_without_panicking() {
let mut s = Session::new();