From 7b10212b5a21d2f9587155ccef65d2e232826607 Mon Sep 17 00:00:00 2001 From: DCM4711 <107349915+DCM4711@users.noreply.github.com> Date: Wed, 14 Oct 2026 22:43:51 +0200 Subject: [PATCH] =?UTF-8?q?Header=20menus:=20Format=20Cells=E2=80=A6=20for?= =?UTF-8?q?=20the=20selected=20rows=20or=20columns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As in Excel, right-clicking a row or column heading offers Format Cells…, between Clear Contents and Row Height… / Column Width…. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/grid.rs | 3 ++ crates/ui-egui/tests/insert_copied_cells.rs | 31 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/crates/ui-egui/src/grid.rs b/crates/ui-egui/src/grid.rs index 97b787ef3..294b94d5e 100644 --- a/crates/ui-egui/src/grid.rs +++ b/crates/ui-egui/src/grid.rs @@ -3118,6 +3118,7 @@ fn header_menu(app: &mut SheetApp, ui: &mut egui::Ui, was_open: bool) { ("Delete", "home.deleteRows"), ("Clear Contents", "edit.clearContents"), ("-", ""), + ("Format Cells…", "ui:formatCells"), ("Row Height…", "ui:rowHeight"), ("AutoFit Row Height", "home.autofitRowHeight"), ("Hide", "home.hideRows"), @@ -3134,6 +3135,7 @@ fn header_menu(app: &mut SheetApp, ui: &mut egui::Ui, was_open: bool) { ("Delete", "home.deleteColumns"), ("Clear Contents", "edit.clearContents"), ("-", ""), + ("Format Cells…", "ui:formatCells"), ("Column Width…", "ui:columnWidth"), ("AutoFit Column Width", "home.autofitColumnWidth"), ("Hide", "home.hideColumns"), @@ -3156,6 +3158,7 @@ fn header_menu(app: &mut SheetApp, ui: &mut egui::Ui, was_open: bool) { match id { "ui:insertPaste" => app.open_dialog("insertPaste", json!({})), "ui:rowHeight" => app.open_dialog("rowHeight", json!({})), + "ui:formatCells" => app.open_dialog("formatCells", json!({})), "ui:columnWidth" => app.open_dialog("columnWidth", json!({})), "edit.copy" | "edit.cut" => { app.copy_to_clipboard(ui.ctx(), id); diff --git a/crates/ui-egui/tests/insert_copied_cells.rs b/crates/ui-egui/tests/insert_copied_cells.rs index 89621f21b..d6ca79f2d 100644 --- a/crates/ui-egui/tests/insert_copied_cells.rs +++ b/crates/ui-egui/tests/insert_copied_cells.rs @@ -58,3 +58,34 @@ fn row_header_menu_inserts_copied_rows() { assert_eq!(value(&h, "A4"), Value::Number(3.0)); assert_eq!(value(&h, "A5"), Value::Number(4.0)); } + +fn right_click_col_header(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 x = geo.cell_rect(sh, CellRef::parse(cell).unwrap()).center().x; + let pos = pos2(x, (geo.rect.top() + geo.cells.top()) / 2.0); + h.input_mut().events.push(Event::PointerMoved(pos)); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE }); + h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); +} + +/// As in Excel, the row and column header menus offer Format Cells… for the selected lines. +#[test] +fn header_menus_open_format_cells() { + for rows in [true, false] { + let mut h = harness(); + if rows { + right_click_row_header(&mut h, "A3"); + } else { + right_click_col_header(&mut h, "B1"); + } + h.get_by_label("Format Cells…").click(); + h.run_steps(2); + let app = h.state(); + assert_eq!(app.dialog.as_ref().map(|d| d.name()), Some("formatCells"), "rows: {rows}"); + let sel = app.session.active().unwrap().selection.a1(); + assert_eq!(sel, if rows { "3:3" } else { "B:B" }); + } +}