Compare commits

...
Author SHA1 Message Date
MaciekandMaciej Malinowski 42acfafcd3 Find and Replace: Undo and Redo reach the sheet while the dialog is open (#2140)
* Find and Replace: Undo and Redo reach the sheet while the dialog is open

Ctrl+Z after Replace All did nothing until the dialog was closed: the open
dialog kept the keyboard from the grid. The dialog now undoes and redoes
the workbook itself unless a text box has focus (there the shortcuts edit
the typed text).

* Find and Replace: Undo and Redo use the sheet's shortcut table

The dialog passed hard-coded keys to edit.undo and edit.redo. It now hands
Cmd/Ctrl+Z, Cmd/Ctrl+Shift+Z and Cmd/Ctrl+Y to ribbon::shortcut, the table
the grid uses, so the dialog and the sheet keep the same bindings. The test
also covers the Mac Redo shortcut (Cmd+Shift+Z).

* fix(find): allow workbook undo when a dialog button has focus

Reserve Undo/Redo for text editing only while a text edit has focus. The regression reproduces the failure with keyboard focus on Replace All, checks both Redo shortcuts, and verifies text-field Undo leaves the sheet unchanged. Regression failed before the fix and passes now. Validation: 1143 UI integration tests pass; only existing missing-glyph failures U+1E9E and U+1EBB remain. WASM, assets, layers and generators pass. Full CI reaches the unchanged Windows CLI clippy::only_used_in_recursion failure in apps/gridcraft-cli/src/check.rs.

* fix(find): block workbook shortcuts behind a modal message

Check app.message before dispatching workbook Undo/Redo. Regression uses an empty Replace All search to open the real error, covers all three shortcuts, and checks Redo after dismissal. Extend text-focus coverage to type and undo actual text. Modal regression fails before the guard and passes after it. Validation: 1144 integration tests pass; two existing missing-glyph failures remain. WASM, assets and layers pass. Full CI still stops at the unchanged Windows CLI clippy::only_used_in_recursion warning.

---------

Co-authored-by: Maciej Malinowski <231036771+webglobecontact-ui@users.noreply.github.com>
2026-11-19 08:37:18 +07:00
3 changed files with 88 additions and 1 deletions
+15
View File
@@ -1,8 +1,23 @@
use egui::Modifiers;
use super::show::ok_cancel;
use super::{Dialog, Json, Key, SheetApp, json};
/// Draws the Find/Replace form with case, whole-cell and workbook options, requests field focus once, and runs find/replace with the current parameters.
pub(super) fn find(app: &mut SheetApp, ui: &mut egui::Ui, d: &mut Dialog) {
// The dialog stays open over the sheet, so Undo and Redo reach the workbook (a Replace All
// is undone without closing it first); inside a text box they edit the typed text instead.
// A modal message blocks workbook shortcuts; otherwise use the grid's own shortcut table.
if app.message.is_none() && !ui.ctx().text_edit_focused() {
let pressed = ui.input_mut(|i| {
[(Modifiers::COMMAND | Modifiers::SHIFT, Key::Z), (Modifiers::COMMAND, Key::Z), (Modifiers::COMMAND, Key::Y)]
.into_iter()
.find(|&(m, key)| i.consume_key(m, key))
});
if let Some((m, key)) = pressed {
crate::ribbon::shortcut(app, key, m);
}
}
ui.horizontal(|ui| {
for tab in ["Find", "Replace"] {
if ui.selectable_label(d.tab == tab, tab).clicked() {
+71
View File
@@ -336,6 +336,77 @@ fn arrows_escape_and_undo() {
assert_eq!(value(&h, "B2"), Value::Empty);
}
#[test]
fn undo_and_redo_reach_the_sheet_while_find_and_replace_is_open() {
let mut h = harness(blank());
for t in ["x1", "x2"] {
text(&mut h, t);
key(&mut h, Key::Enter, Modifiers::NONE);
}
h.state_mut().open_dialog("find", json!({"replace": true}));
h.run_steps(3);
if let Some(d) = h.state_mut().dialog.as_mut() {
d.values.insert("what".into(), json!("x"));
d.values.insert("with".into(), json!("y"));
}
h.run_steps(2);
h.get_by_label("Replace All").click();
h.run_steps(3);
assert_eq!((value(&h, "A1"), value(&h, "A2")), (Value::from("y1"), Value::from("y2")));
// Keyboard focus on a button must not reserve Undo/Redo for text editing.
h.get_by_label("Replace All").focus();
h.run_steps(2);
assert!(h.ctx.egui_wants_keyboard_input());
assert!(!h.ctx.text_edit_focused());
key(&mut h, Key::Z, Modifiers::COMMAND);
assert!(h.state().dialog.is_some(), "the dialog stays open");
assert_eq!((value(&h, "A1"), value(&h, "A2")), (Value::from("x1"), Value::from("x2")), "one Undo takes back the whole Replace All");
key(&mut h, Key::Y, Modifiers::COMMAND);
assert_eq!((value(&h, "A1"), value(&h, "A2")), (Value::from("y1"), Value::from("y2")));
// The Mac Redo shortcut works too, as it does on the sheet.
key(&mut h, Key::Z, Modifiers::COMMAND);
assert_eq!(value(&h, "A1"), Value::from("x1"));
key(&mut h, Key::Z, Modifiers::COMMAND | Modifiers::SHIFT);
assert_eq!((value(&h, "A1"), value(&h, "A2")), (Value::from("y1"), Value::from("y2")));
assert!(h.state().dialog.is_some(), "the dialog is still open");
h.get_by_label("Find what:").focus();
h.run_steps(2);
assert!(h.ctx.text_edit_focused());
let before = h.state().dialog.as_ref().unwrap().values.get("what").cloned();
h.input_mut().events.push(Event::Text("extra".into()));
h.run_steps(2);
assert_ne!(h.state().dialog.as_ref().unwrap().values.get("what"), before.as_ref());
key(&mut h, Key::Z, Modifiers::COMMAND);
assert_eq!(h.state().dialog.as_ref().unwrap().values.get("what"), before.as_ref(), "Undo restores the Find field");
assert_eq!((value(&h, "A1"), value(&h, "A2")), (Value::from("y1"), Value::from("y2")), "text-field Undo leaves the sheet alone");
}
#[test]
fn find_message_blocks_workbook_undo_and_redo() {
let mut session = blank();
session.execute("cell.set", json!({"cell": "A1", "input": "first"})).unwrap();
session.execute("cell.set", json!({"cell": "A1", "input": "second"})).unwrap();
session.execute("edit.undo", json!({})).unwrap();
let mut h = harness(session);
h.state_mut().open_dialog("find", json!({"replace": true}));
h.run_steps(3);
// An empty search raises the real modal error over Find and Replace.
h.get_by_label("Replace All").click();
h.run_steps(3);
assert!(h.state().message.is_some());
assert!(!h.ctx.text_edit_focused());
for (key_code, modifiers) in [(Key::Z, Modifiers::COMMAND), (Key::Y, Modifiers::COMMAND), (Key::Z, Modifiers::COMMAND | Modifiers::SHIFT)] {
key(&mut h, key_code, modifiers);
assert_eq!(value(&h, "A1"), Value::from("first"), "the message blocks workbook shortcuts");
assert!(h.state().message.is_some());
}
h.state_mut().message = None;
h.run_steps(2);
h.get_by_label("Replace All").focus();
h.run_steps(2);
key(&mut h, Key::Y, Modifiers::COMMAND);
assert_eq!(value(&h, "A1"), Value::from("second"), "Redo works again after dismissing the message");
}
#[test]
fn shift_arrows_in_point_mode_extend_from_the_pointed_cell() {
let mut s = blank();
+2 -1
View File
@@ -1,6 +1,6 @@
# UI parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-05 · **Change:** minor (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-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
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
@@ -275,6 +275,7 @@ scrollbar bugs 2–4 · pixel/feel pass against observed Excel 7–12.
| 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 |
| 2026-11-04 | minor | Align wrapped and unwrapped cells with the same vertical margins; regressions compare numbers with mixed CJK/Latin text, including explicit line breaks |
| 2026-11-02 | minor | Form controls: buttons, sliders (scroll bars) and spin buttons placed, worked, selected and edited on the sheet (Insert › Controls, Assign Action, Format Control); catalog 281 / 296 |
| 2026-11-03 | minor | Find and Replace: workbook Undo/Redo works with a keyboard-focused button; focused text fields keep text-editing Undo, and a modal message blocks workbook shortcuts. Regression covers Replace All, both Redo shortcuts, actual text undo, and an error message |
| 2026-11-03 | minor | Highlight the active cell's row: a global preference that tints the whole row, off by default |
| 2026-11-03 | minor | The formula bar's bottom edge is a resize handle: dragging it sets the bar's height in whole lines, up to half the window, and dragging it to one line collapses it; expanding (the chevron, Ctrl+Shift+U) returns to the dragged height, which is kept with the UI preferences. `view.expandFormulaBar {lines}` sets it (#1246) |
| 2026-11-03 | minor | Cell context menu on a cell with a link: Edit Hyperlink… (the link dialog, titled Edit Hyperlink and filled with the link), Open Hyperlink and Remove Hyperlink, as in Excel, instead of Link… (#2120) |