From 28086016fe2743e1f42db5634d40cd67d84e7944 Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Mon, 26 Oct 2026 09:21:43 -0500 Subject: [PATCH 1/6] i18n: Paste Special's Add and Text to Columns' Comma get their own keys "Add" is both a Paste Special operation and the Solver's Add button, and "Comma" both the Text to Columns delimiter and the Comma cell style. One translation can't fit both (Spanish Excel: Sumar vs Agregar, Coma vs Millares), and open PRs are about to translate the Solver button and the cell-style gallery. The two dialog options now use `Paste Special|Add` and `Text to Columns|Comma`; English shows the same labels and every catalog carries its current translation onto the new key, so nothing visible changes. A test checks both. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs.rs | 10 ++++++++-- crates/ui-egui/src/i18n.rs | 17 +++++++++++++++++ crates/ui-egui/src/i18n/el.rs | 2 ++ crates/ui-egui/src/i18n/it.rs | 2 ++ crates/ui-egui/src/i18n/ja.rs | 2 ++ crates/ui-egui/src/i18n/pl.rs | 2 ++ crates/ui-egui/src/i18n/pt.rs | 2 ++ crates/ui-egui/src/i18n/ro.rs | 2 ++ crates/ui-egui/src/i18n/uk.rs | 2 ++ docs/localization-parity.md | 3 ++- 10 files changed, 41 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 47b215302..2513c1e11 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -506,7 +506,13 @@ impl Dialog { Choice { key: "operation", label: "Operation", - options: vec![("none", "None"), ("add", "Add"), ("subtract", "Subtract"), ("multiply", "Multiply"), ("divide", "Divide")], + options: vec![ + ("none", "None"), + ("add", "Paste Special|Add"), + ("subtract", "Subtract"), + ("multiply", "Multiply"), + ("divide", "Divide"), + ], }, Check { key: "skipBlanks", label: "Skip blanks" }, Check { key: "transpose", label: "Transpose (E)" }, @@ -648,7 +654,7 @@ impl Dialog { vec![ Check { key: "tab", label: "Tab" }, Check { key: "semicolon", label: "Semicolon" }, - Check { key: "comma", label: "Comma" }, + Check { key: "comma", label: "Text to Columns|Comma" }, Check { key: "space", label: "Space" }, Text { key: "other", label: "Other:" }, Check { key: "treatConsecutive", label: "Treat consecutive delimiters as one" }, diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 0ffd0ad09..6e4b7c052 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -418,6 +418,23 @@ mod tests { } } + #[test] + fn paste_special_add_and_text_to_columns_comma_have_their_own_keys() { + // "Add" is also the Solver button and "Comma" also the cell style (Spanish Excel: Sumar + // vs Agregar, Coma vs Millares), so the two dialog options are keyed by context. English + // shows the plain label, and every catalog shows what it showed before the split. + for (keyed, plain) in [("Paste Special|Add", "Add"), ("Text to Columns|Comma", "Comma")] { + assert_eq!(Language::En.tr(keyed), plain); + for language in Language::ALL { + let shown = language.tr(keyed); + assert!(!shown.contains('|'), "{} shows a context prefix for {keyed}: {shown}", language.code()); + if language.tr(plain) != plain { + assert_eq!(shown, language.tr(plain), "{}: {keyed}", language.code()); + } + } + } + } + #[test] fn translations_never_show_the_context_prefix() { // `tr` returns a found translation as it is, so a catalog that keeps `context|` in its diff --git a/crates/ui-egui/src/i18n/el.rs b/crates/ui-egui/src/i18n/el.rs index 2a7449fd6..d30bd20e0 100644 --- a/crates/ui-egui/src/i18n/el.rs +++ b/crates/ui-egui/src/i18n/el.rs @@ -667,6 +667,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Values and number formats" => "Τιμές και μορφές αριθμών", "Operation" => "Πράξη", "Add" => "Πρόσθεση", + "Paste Special|Add" => "Πρόσθεση", "Subtract" => "Αφαίρεση", "Multiply" => "Πολλαπλασιασμός", "Divide" => "Διαίρεση", @@ -704,6 +705,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Tab" => "Στηλοθέτης", "Semicolon" => "Ερωτηματικό (;)", "Comma" => "Κόμμα", + "Text to Columns|Comma" => "Κόμμα", "Space" => "Διάστημα", "Other:" => "Άλλο:", "Treat consecutive delimiters as one" => "Αντιμετώπιση διαδοχικών διαχωριστικών ως ενός", diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index 24fa45c95..631c7cf07 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -549,6 +549,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Values and number formats" => "Valori e formati numero", "Operation" => "Operazione", "Add" => "Aggiungi", + "Paste Special|Add" => "Aggiungi", "Subtract" => "Sottrai", "Multiply" => "Moltiplica", "Divide" => "Dividi", @@ -588,6 +589,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Tab" => "Tabulazione", "Semicolon" => "Punto e virgola", "Comma" => "Virgola", + "Text to Columns|Comma" => "Virgola", "Space" => "Spazio", "Other:" => "Altro:", "Treat consecutive delimiters as one" => "Considera delimitatori consecutivi come uno solo", diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index a659da744..d6fb4352d 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -566,6 +566,7 @@ pub(super) const DIALOGS: &[(&str, &str)] = &[ ("Values and number formats", "値と数値の書式"), ("Operation", "演算"), ("Add", "加算"), + ("Paste Special|Add", "加算"), ("Subtract", "減算"), ("Multiply", "乗算"), ("Divide", "除算"), @@ -605,6 +606,7 @@ pub(super) const DIALOGS: &[(&str, &str)] = &[ ("Tab", "タブ"), ("Semicolon", "セミコロン"), ("Comma", "コンマ"), + ("Text to Columns|Comma", "コンマ"), ("Space", "スペース"), ("Other:", "その他:"), ("Treat consecutive delimiters as one", "連続した区切り文字は 1 文字として扱う"), diff --git a/crates/ui-egui/src/i18n/pl.rs b/crates/ui-egui/src/i18n/pl.rs index d232a6e0d..279bb1e57 100644 --- a/crates/ui-egui/src/i18n/pl.rs +++ b/crates/ui-egui/src/i18n/pl.rs @@ -540,6 +540,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Values and number formats" => "Wartości i formaty liczb", "Operation" => "Operacja", "Add" => "Dodaj", + "Paste Special|Add" => "Dodaj", "Subtract" => "Odejmij", "Multiply" => "Pomnóż", "Divide" => "Podziel", @@ -579,6 +580,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Tab" => "Tabulator", "Semicolon" => "Średnik", "Comma" => "Przecinek", + "Text to Columns|Comma" => "Przecinek", "Space" => "Spacja", "Other:" => "Inny:", "Treat consecutive delimiters as one" => "Traktuj kolejne ograniczniki jako jeden", diff --git a/crates/ui-egui/src/i18n/pt.rs b/crates/ui-egui/src/i18n/pt.rs index d93054309..4f6c0f4f7 100644 --- a/crates/ui-egui/src/i18n/pt.rs +++ b/crates/ui-egui/src/i18n/pt.rs @@ -574,6 +574,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Values and number formats" => "Valores e formatos de número", "Operation" => "Operação", "Add" => "Adicionar", + "Paste Special|Add" => "Adicionar", "Subtract" => "Subtrair", "Multiply" => "Multiplicar", "Divide" => "Dividir", @@ -613,6 +614,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Tab" => "Tabulação", "Semicolon" => "Ponto e vírgula", "Comma" => "Vírgula", + "Text to Columns|Comma" => "Vírgula", "Space" => "Espaço", "Other:" => "Outros:", "Treat consecutive delimiters as one" => "Considerar delimitadores consecutivos como um só", diff --git a/crates/ui-egui/src/i18n/ro.rs b/crates/ui-egui/src/i18n/ro.rs index 0876ac50f..f2c7395cb 100644 --- a/crates/ui-egui/src/i18n/ro.rs +++ b/crates/ui-egui/src/i18n/ro.rs @@ -546,6 +546,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Values and number formats" => "Valori și formate de număr", "Operation" => "Operație", "Add" => "Adăugare", + "Paste Special|Add" => "Adăugare", "Subtract" => "Scădere", "Multiply" => "Înmulțire", "Divide" => "Împărțire", @@ -585,6 +586,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Tab" => "Tab", "Semicolon" => "Punct și virgulă", "Comma" => "Virgulă", + "Text to Columns|Comma" => "Virgulă", "Space" => "Spațiu", "Other:" => "Altele:", "Treat consecutive delimiters as one" => "Delimitatorii consecutivi se tratează ca unul singur", diff --git a/crates/ui-egui/src/i18n/uk.rs b/crates/ui-egui/src/i18n/uk.rs index 4374cc135..53cd57f76 100644 --- a/crates/ui-egui/src/i18n/uk.rs +++ b/crates/ui-egui/src/i18n/uk.rs @@ -544,6 +544,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Values and number formats" => "Values and number formats", "Operation" => "Operation", "Add" => "Add", + "Paste Special|Add" => "Add", "Subtract" => "Subtract", "Multiply" => "Multiply", "Divide" => "Divide", @@ -583,6 +584,7 @@ pub(super) fn translate(text: &str) -> Option<&'static str> { "Tab" => "Tab", "Semicolon" => "Semicolon", "Comma" => "Comma", + "Text to Columns|Comma" => "Comma", "Space" => "Space", "Other:" => "Other:", "Treat consecutive delimiters as one" => "Treat consecutive delimiters as one", diff --git a/docs/localization-parity.md b/docs/localization-parity.md index 1de2927ac..eef37d88a 100644 --- a/docs/localization-parity.md +++ b/docs/localization-parity.md @@ -1,6 +1,6 @@ # Localization parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-10 · **Change:** minor (Ukrainian Chart is Діаграма); previously minor (Diagram and Decorative Text labels, Diagram distinct from Chart); previously minor (CJK fallback baseline alignment); previously minor (Arabic bidi display, editing and cell reading direction; missing translations are listed by `cargo xtask i18n-report` and never fail a check); previously minor (Arabic font fallback; missing translations are listed by `cargo xtask i18n-report` and never fail a check); previously minor (number formats honour the `B1`/`B2` calendar prefixes, checked against Excel; earlier: missing translations are listed by `cargo xtask i18n-report` and never fail a check; Arabic text sorts by its letters, not its vowel marks); previously minor (AutoFit estimates Arabic text width from measured glyph widths); previously minor (missing translations are listed by `cargo xtask i18n-report` and never fail a check; Arabic text sorts by its letters, not its vowel marks) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-14 · **Change:** minor (Paste Special's Add and Text to Columns' Comma get their own keys); previously minor (Ukrainian Chart is Діаграма); previously minor (Diagram and Decorative Text labels, Diagram distinct from Chart); previously minor (CJK fallback baseline alignment); previously minor (Arabic bidi display, editing and cell reading direction; missing translations are listed by `cargo xtask i18n-report` and never fail a check); previously minor (Arabic font fallback; missing translations are listed by `cargo xtask i18n-report` and never fail a check); previously minor (number formats honour the `B1`/`B2` calendar prefixes, checked against Excel; earlier: missing translations are listed by `cargo xtask i18n-report` and never fail a check; Arabic text sorts by its letters, not its vowel marks); previously minor (AutoFit estimates Arabic text width from measured glyph widths); previously minor (missing translations are listed by `cargo xtask i18n-report` and never fail a check; Arabic text sorts by its letters, not its vowel marks) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4 Per-language status against Excel, which ships its UI in dozens of languages (Windows language packs cover 100+), with localized function names, argument separators, number and date formats, @@ -140,6 +140,7 @@ language (none so far) and of localized function names. | 2026-10-26 | minor | Arabic text renders in cells and the interface: a system Arabic face (Tahoma, Arial or Segoe UI on Windows, Geeza Pro on macOS, Noto Sans or Naskh Arabic on Linux) joins the script fallbacks, fontconfig's Arabic choice, when it has Arabic letters, leads the Arabic fallbacks and draws Arabic wherever the UI or cell font has none, such as the default cell fonts (part of #229; a UI font with Arabic of its own, such as DejaVu Sans in the Flatpak, still draws interface Arabic, left for a follow-up), and craft-fonts' Noto Sans Arabic is a required face allowed on the web. Workbook fonts without Arabic keep every script fallback. Shaping and bidirectional layout remain separate work | | 2026-10-27 | minor | Number formats honour the `B1`/`B2` calendar prefixes: never shown; `B2` renders year, month, day and Arabic month and weekday names in the tabular Hijri calendar (1 Jan 2001 = 6 Shawwal 1421; leap years 2, 5, 7, 10, 13, 15, 18, 21, 24, 26 and 29 of the 30-year cycle, which is what Excel shows). Checked against Excel 16.0 (build 20527, en-US) on every serial and about 1,700 format/value pairs: a locale or currency tag before `B2` keeps the date Gregorian, a misplaced `B` and digit or a prefix before a number format is rejected, serial 60 has no Hijri date, serial 0 shows as serial 1, two-word month names use a no-break space. Not matched: Excel's weekday/month-name mix-ups in one `B2` section and its weekday-only quirks | | 2026-10-27 | minor | AutoFit column width, wrapped-row height and PivotTable column fit estimate Arabic letters at ~0.48 em (measured 0.36–0.53 em shaped, Noto Sans/Naskh Arabic and DejaVu Sans) instead of 1 em, Arabic-Indic digits as wide as ASCII digits, and give vowel marks and direction marks no width; vowelled Arabic no longer fits ~3.5× too wide | +| 2026-10-26 | minor | Paste Special's Add operation and Text to Columns' Comma delimiter are keyed `Paste Special|Add` and `Text to Columns|Comma`, so they can be translated apart from the Solver's Add button and the Comma cell style (Spanish: Sumar vs Agregar, Coma vs Millares); every catalog keeps the text it showed | | 2026-10-23 | minor | Missing translations are reported, never a failure: `cargo xtask i18n-report` prints, per language, the strings other catalogs translate and it lacks (plus Spanish function help rows keyed by English the function catalog no longer has) and always passes; `cargo xtask ci` runs it first. Coverage and per-language parity tests and tests of one language's exact wording are gone; UI tests take the expected text from the catalog. Duplicate-key, placeholder, context-prefix and line-shape checks stay | | 2026-10-21 | minor | Romanian interface (`ro`, Română): 970 labels covering every key of the other catalogs (`crates/ui-egui/src/i18n/ro.rs`), `ro-*` system locales, the View-tab switcher and `app.language.set`; context keys show no prefix (File › Options test). English formulas and formats; AI-assisted draft pending native-speaker review | | 2026-10-20 | minor | Japanese: furigana (`rPh` phonetic runs and `` in `xl/sharedStrings.xml`) is no longer deleted by an open + save; it is kept on the workbook and written back (a `` without runs is kept too, while duplicate texts with different readings keep only the first, reported on open). Display of the readings is still missing (`crates/xlsx/src/tests/phonetic_tests.rs`) | From ad7ec8d775166adb622ccd36879ab56123c06d65 Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Mon, 26 Oct 2026 09:23:49 -0500 Subject: [PATCH 2/6] i18n: the key-split test lets a catalog translate the two uses differently The test required `Paste Special|Add` and `Text to Columns|Comma` to show the same text as the plain keys, which forbids the very split it guards (Spanish: Sumar vs Agregar). It now checks that a catalog translating the plain label also translates the keyed one. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/i18n.rs | 5 +++-- docs/localization-parity.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 6e4b7c052..4453a1446 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -422,14 +422,15 @@ mod tests { fn paste_special_add_and_text_to_columns_comma_have_their_own_keys() { // "Add" is also the Solver button and "Comma" also the cell style (Spanish Excel: Sumar // vs Agregar, Coma vs Millares), so the two dialog options are keyed by context. English - // shows the plain label, and every catalog shows what it showed before the split. + // shows the plain label, and a catalog that translates the plain label translates the + // keyed one too, so the dialog option doesn't fall back to English. for (keyed, plain) in [("Paste Special|Add", "Add"), ("Text to Columns|Comma", "Comma")] { assert_eq!(Language::En.tr(keyed), plain); for language in Language::ALL { let shown = language.tr(keyed); assert!(!shown.contains('|'), "{} shows a context prefix for {keyed}: {shown}", language.code()); if language.tr(plain) != plain { - assert_eq!(shown, language.tr(plain), "{}: {keyed}", language.code()); + assert_ne!(shown, plain, "{} translates {plain:?} but not {keyed:?}", language.code()); } } } diff --git a/docs/localization-parity.md b/docs/localization-parity.md index eef37d88a..759c813e1 100644 --- a/docs/localization-parity.md +++ b/docs/localization-parity.md @@ -140,7 +140,7 @@ language (none so far) and of localized function names. | 2026-10-26 | minor | Arabic text renders in cells and the interface: a system Arabic face (Tahoma, Arial or Segoe UI on Windows, Geeza Pro on macOS, Noto Sans or Naskh Arabic on Linux) joins the script fallbacks, fontconfig's Arabic choice, when it has Arabic letters, leads the Arabic fallbacks and draws Arabic wherever the UI or cell font has none, such as the default cell fonts (part of #229; a UI font with Arabic of its own, such as DejaVu Sans in the Flatpak, still draws interface Arabic, left for a follow-up), and craft-fonts' Noto Sans Arabic is a required face allowed on the web. Workbook fonts without Arabic keep every script fallback. Shaping and bidirectional layout remain separate work | | 2026-10-27 | minor | Number formats honour the `B1`/`B2` calendar prefixes: never shown; `B2` renders year, month, day and Arabic month and weekday names in the tabular Hijri calendar (1 Jan 2001 = 6 Shawwal 1421; leap years 2, 5, 7, 10, 13, 15, 18, 21, 24, 26 and 29 of the 30-year cycle, which is what Excel shows). Checked against Excel 16.0 (build 20527, en-US) on every serial and about 1,700 format/value pairs: a locale or currency tag before `B2` keeps the date Gregorian, a misplaced `B` and digit or a prefix before a number format is rejected, serial 60 has no Hijri date, serial 0 shows as serial 1, two-word month names use a no-break space. Not matched: Excel's weekday/month-name mix-ups in one `B2` section and its weekday-only quirks | | 2026-10-27 | minor | AutoFit column width, wrapped-row height and PivotTable column fit estimate Arabic letters at ~0.48 em (measured 0.36–0.53 em shaped, Noto Sans/Naskh Arabic and DejaVu Sans) instead of 1 em, Arabic-Indic digits as wide as ASCII digits, and give vowel marks and direction marks no width; vowelled Arabic no longer fits ~3.5× too wide | -| 2026-10-26 | minor | Paste Special's Add operation and Text to Columns' Comma delimiter are keyed `Paste Special|Add` and `Text to Columns|Comma`, so they can be translated apart from the Solver's Add button and the Comma cell style (Spanish: Sumar vs Agregar, Coma vs Millares); every catalog keeps the text it showed | +| 2026-10-26 | minor | Paste Special's Add operation and Text to Columns' Comma delimiter are keyed `Paste Special\|Add` and `Text to Columns\|Comma`, so they can be translated apart from the Solver's Add button and the Comma cell style (Spanish: Sumar vs Agregar, Coma vs Millares); every catalog keeps the text it showed | | 2026-10-23 | minor | Missing translations are reported, never a failure: `cargo xtask i18n-report` prints, per language, the strings other catalogs translate and it lacks (plus Spanish function help rows keyed by English the function catalog no longer has) and always passes; `cargo xtask ci` runs it first. Coverage and per-language parity tests and tests of one language's exact wording are gone; UI tests take the expected text from the catalog. Duplicate-key, placeholder, context-prefix and line-shape checks stay | | 2026-10-21 | minor | Romanian interface (`ro`, Română): 970 labels covering every key of the other catalogs (`crates/ui-egui/src/i18n/ro.rs`), `ro-*` system locales, the View-tab switcher and `app.language.set`; context keys show no prefix (File › Options test). English formulas and formats; AI-assisted draft pending native-speaker review | | 2026-10-20 | minor | Japanese: furigana (`rPh` phonetic runs and `` in `xl/sharedStrings.xml`) is no longer deleted by an open + save; it is kept on the workbook and written back (a `` without runs is kept too, while duplicate texts with different readings keep only the first, reported on open). Display of the readings is still missing (`crates/xlsx/src/tests/phonetic_tests.rs`) | From f32fefddcf6961da5bc101090dfac4154542e006 Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Mon, 2 Nov 2026 07:34:22 -0600 Subject: [PATCH 3/6] Tables never hold merged cells, which Excel removes the table for on open A table with a merged cell in it opened in Excel with the repair prompt, and Excel removed the table and its AutoFilter ("Removed Feature: Table from /xl/tables/table1.xml"). GridCraft let merged cells into a table four ways; each now does what Excel does: - Merge Cells, Merge & Center and Merge Across refuse a range that touches a table ("You can't merge cells in a table."). Unmerging is still allowed, so a file that has one can be fixed. - Insert Table / Format as Table and Resize Table unmerge the merged cells the table covers (observed: Excel creates the table and A2:B2 is no longer merged). - Paste brings merged areas along, except into a table, where the cells arrive unmerged. The command-sequence fuzzer checks the invariant (it found the paste case, seed 230). --- crates/engine/src/cmd/edit/paste_special.rs | 5 ++ crates/engine/src/cmd/extra/data.rs | 2 + crates/engine/src/cmd/format.rs | 5 ++ crates/engine/src/cmd/insert.rs | 7 +++ crates/engine/src/tests.rs | 60 +++++++++++++++++++ .../engine/tests/it/command_sequence_fuzz.rs | 6 +- crates/engine/tests/it/sheet_copy_spill.rs | 2 +- 7 files changed, 85 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/edit/paste_special.rs b/crates/engine/src/cmd/edit/paste_special.rs index c90dd9ec8..0c2f17a3d 100644 --- a/crates/engine/src/cmd/edit/paste_special.rs +++ b/crates/engine/src/cmd/edit/paste_special.rs @@ -361,6 +361,11 @@ pub(super) fn paste_special(s: &mut Session, p: &Json) -> Result { if let (Some(a), Some(b)) = (m.start.offset(dr, dc), m.end.offset(dr, dc)) { let nm = RangeRef::new(a, b); let sh = cx.sheet_mut(dest_sheet)?; + // A table can't hold merged cells (Excel removes the table on open): the + // cells are pasted there unmerged. + if sh.tables.iter().any(|t| t.range.intersects(&nm)) { + continue; + } sh.merges.retain(|x| !x.intersects(&nm)); sh.merges.push(nm); } diff --git a/crates/engine/src/cmd/extra/data.rs b/crates/engine/src/cmd/extra/data.rs index 5af7df0a8..9940ffc45 100644 --- a/crates/engine/src/cmd/extra/data.rs +++ b/crates/engine/src/cmd/extra/data.rs @@ -37,6 +37,8 @@ pub(super) fn table_resize(s: &mut Session, p: &Json) -> Result { } t.columns = cols; t.range = r; + // A table can't hold merged cells: those it now covers are unmerged, as by Insert Table. + sheet.merges.retain(|m| !m.intersects(&r)); cx.structural = true; Ok(Json::Null) }) diff --git a/crates/engine/src/cmd/format.rs b/crates/engine/src/cmd/format.rs index 90213a5e1..d512b7a0c 100644 --- a/crates/engine/src/cmd/format.rs +++ b/crates/engine/src/cmd/format.rs @@ -637,6 +637,11 @@ fn merge(s: &mut Session, p: &Json, how: &str) -> Result { let ranges = target_ranges(s, p)?; let how = if how == "center" && s.doc()?.wb.sheet(sheet).is_some_and(|sh| ranges.iter().all(|r| sh.merges.contains(r))) { "unmerge" } else { how }; + // Excel has no merged cells in a table (a file with one loses the table when Excel opens it): + // merging there is refused, unmerging is still allowed. + if how != "unmerge" && s.doc()?.wb.sheet(sheet).is_some_and(|sh| sh.tables.iter().any(|t| ranges.iter().any(|r| t.range.intersects(r)))) { + return Err(EngineError::Other("You can't merge cells in a table.".into())); + } edit(s, |cx| { let mut touched = Vec::new(); // Areas whose merging changes: a merged cell blocks a dynamic array's spill. diff --git a/crates/engine/src/cmd/insert.rs b/crates/engine/src/cmd/insert.rs index 4bd564db3..f88c6040f 100644 --- a/crates/engine/src/cmd/insert.rs +++ b/crates/engine/src/cmd/insert.rs @@ -334,6 +334,13 @@ fn insert_table(s: &mut Session, p: &Json) -> Result { RangeRef::new(r.start, CellRef::new((r.end.row + 1).min(MAX_ROWS - 1), r.end.col)) }; let sh = cx.sheet_mut(sheet)?; + // As in Excel, the table unmerges the merged cells it covers: a table can't hold them. + let merged = sh.merges.len(); + sh.merges.retain(|m| !m.intersects(&r)); + if sh.merges.len() != merged { + cx.structural = true; + } + let sh = cx.sheet_mut(sheet)?; let mut names: Vec = Vec::new(); // Lower-case names taken, and the next suffix for each header, so that thousands of equal // headers don't take cubic time. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index f000eb9fe..5cc071d5a 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6728,3 +6728,63 @@ fn history_charges_the_storage_of_empty_comment_replies() { // 500 replies of no text are still 500 elements. assert!(crate::sheet_text_bytes(&sheet) >= 500 * std::mem::size_of::<(String, String)>()); } + +#[test] +fn tables_never_hold_merged_cells() { + // Excel removes a table that contains a merged cell when it opens the file. Merging in a + // table is refused; making or resizing a table over merged cells unmerges them; pasting into + // a table skips the merges. + let base = || { + let mut s = s(); + s.execute("range.setValues", json!({"range": "A1:D4", "values": [["A", "B", "C", "D"], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]})) + .unwrap(); + s + }; + let merges = |s: &Session| s.doc().unwrap().wb.active().unwrap().merges.clone(); + + let mut s = base(); + s.execute("insert.table", json!({"range": "A1:C4"})).unwrap(); + for id in ["home.mergeCells", "home.mergeCenter", "home.mergeAcross"] { + for range in ["A2:B2", "A1:B1", "C3:D3"] { + let e = s.execute(id, json!({"range": range})).unwrap_err().to_string(); + assert!(e.contains("can't merge cells in a table"), "{id} {range}: {e}"); + } + } + assert!(merges(&s).is_empty()); + s.execute("home.mergeCells", json!({"range": "E2:F2"})).unwrap(); + assert_eq!(merges(&s), vec![gridcraft_core::RangeRef::parse("E2:F2").unwrap()]); + + // A table over merged cells unmerges them; undo brings them back. + let mut s = base(); + s.execute("home.mergeCells", json!({"range": "A2:B2"})).unwrap(); + s.execute("home.mergeCells", json!({"range": "C3:D4"})).unwrap(); + s.execute("home.mergeCells", json!({"range": "F1:G1"})).unwrap(); + s.execute("insert.table", json!({"range": "A1:C4"})).unwrap(); + assert_eq!(merges(&s), vec![gridcraft_core::RangeRef::parse("F1:G1").unwrap()]); + s.execute("edit.undo", json!({})).unwrap(); + assert_eq!(merges(&s).len(), 3); + s.execute("edit.redo", json!({})).unwrap(); + + // Resizing a table over merged cells unmerges them too. + let mut s = base(); + s.execute("insert.table", json!({"range": "A1:B4", "name": "T"})).unwrap(); + s.execute("home.mergeCells", json!({"range": "C2:D2"})).unwrap(); + s.execute("table.resize", json!({"table": "T", "range": "A1:C4"})).unwrap(); + assert!(merges(&s).is_empty()); + + // Merged cells pasted into a table arrive unmerged; elsewhere they stay merged. + s.execute("home.mergeCells", json!({"range": "E2:F3"})).unwrap(); + s.execute("edit.copy", json!({"range": "E2:F3"})).unwrap(); + s.execute("edit.paste", json!({"at": "A2"})).unwrap(); + s.execute("edit.paste", json!({"at": "H2"})).unwrap(); + assert_eq!(merges(&s), vec![gridcraft_core::RangeRef::parse("E2:F3").unwrap(), gridcraft_core::RangeRef::parse("H2:I3").unwrap()]); + + // The saved file has no merge inside the table. + let saved = s.execute("file.saveBytes", json!({"format": "xlsx"})).unwrap(); + let bytes = crate::io::base64_decode(saved["base64"].as_str().unwrap()).unwrap(); + let (back, _) = crate::io::open_bytes("t.xlsx", &bytes).unwrap(); + let sh = back.active().unwrap(); + assert_eq!(sh.tables.len(), 1); + assert_eq!(sh.tables[0].range, gridcraft_core::RangeRef::parse("A1:C4").unwrap()); + assert!(sh.merges.iter().all(|m| sh.tables.iter().all(|t| !t.range.intersects(m)))); +} diff --git a/crates/engine/tests/it/command_sequence_fuzz.rs b/crates/engine/tests/it/command_sequence_fuzz.rs index 89b3e9186..949f63753 100644 --- a/crates/engine/tests/it/command_sequence_fuzz.rs +++ b/crates/engine/tests/it/command_sequence_fuzz.rs @@ -12,7 +12,7 @@ //! and saving, reloading or recalculating never panics either; //! - a non-undoable command never changes cell content (it would be lost to undo); //! - the structure stays valid: active sheet in range, sheet and table names valid and unique, -//! merges and tables on the sheet and not overlapping, legacy arrays anchored at their +//! merges and tables on the sheet and not overlapping (nor a merge inside a table), legacy arrays anchored at their //! top-left cell, the selection on the sheet; //! - a full recalculation from scratch gives the values the incremental recalculation left //! (catches stale dependency graphs); @@ -408,6 +408,10 @@ fn structure_problem(wb: &Workbook, sel: &gridcraft_engine::Selection) -> Option if let Some(o) = sh.tables.iter().skip(k + 1).find(|o| overlaps(&t.range, &o.range)) { return Some(format!("{}: tables `{}` ({}) and `{}` ({}) overlap", sh.name, t.name, t.range, o.name, o.range)); } + // Excel removes a table that holds a merged cell when it opens the file. + if let Some(m) = sh.merges.iter().find(|m| overlaps(&t.range, m)) { + return Some(format!("{}: table `{}` ({}) holds merged cells {m}", sh.name, t.name, t.range)); + } } } if sel.ranges.is_empty() || !sel.active.is_valid() || sel.ranges.iter().any(|r| !r.start.is_valid() || !r.end.is_valid()) { diff --git a/crates/engine/tests/it/sheet_copy_spill.rs b/crates/engine/tests/it/sheet_copy_spill.rs index aed68baf9..481f9889e 100644 --- a/crates/engine/tests/it/sheet_copy_spill.rs +++ b/crates/engine/tests/it/sheet_copy_spill.rs @@ -17,7 +17,7 @@ fn value(s: &Session, sheet: &str, cell: &str) -> Value { fn copied_sheet_keeps_spill_values_through_full_recalc() { let mut s = Session::new(); run(&mut s, "file.new", json!({"sample": "grades"})); - run(&mut s, "home.mergeCells", json!({"range": "F:H"})); + run(&mut s, "home.mergeCells", json!({"range": "F15:H20"})); run(&mut s, "cell.set", json!({"cell": "J54", "input": "=SEQUENCE(5)*C6"})); run(&mut s, "selection.set", json!({"range": "15:15"})); run(&mut s, "sheet.move", json!({"copy": true, "sheet": 0, "to": 1})); From 637e7809f0644a7c62ab6fd23eb8a0e4a2a8b6ba Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:39:40 +0200 Subject: [PATCH 4/6] Make HYPERLINK formula cells behave as clickable links Fixes #2230 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/calc/src/lib.rs | 2 +- crates/engine/src/cmd/insert/links.rs | 4 +-- crates/engine/src/cmd/inspect.rs | 2 +- crates/engine/src/links.rs | 39 ++++++++++++++++++++++++++- crates/engine/src/tests.rs | 15 +++++++++++ crates/ui-egui/src/grid/interact.rs | 4 +-- crates/ui-egui/src/grid/show.rs | 2 +- 7 files changed, 60 insertions(+), 8 deletions(-) diff --git a/crates/calc/src/lib.rs b/crates/calc/src/lib.rs index 794a3f97f..92aa9526c 100644 --- a/crates/calc/src/lib.rs +++ b/crates/calc/src/lib.rs @@ -12,7 +12,7 @@ mod trimrange; pub use eval::{Area, SPECIAL_FUNCTIONS, is_known_function}; pub use precision::DisplayedPrecision; -pub use recalc::{Bounded, Calc, Key, evaluate, evaluate_bounded, now_serial}; +pub use recalc::{Bounded, Calc, Key, evaluate, evaluate_bounded, evaluate_expr, now_serial}; #[cfg(test)] mod tests; diff --git a/crates/engine/src/cmd/insert/links.rs b/crates/engine/src/cmd/insert/links.rs index c90fc946a..b0b489295 100644 --- a/crates/engine/src/cmd/insert/links.rs +++ b/crates/engine/src/cmd/insert/links.rs @@ -56,10 +56,10 @@ pub(super) fn open_link(s: &mut Session, p: &Json) -> Result { None => { let sheet = target_sheet(s, p)?; let at = cell_param_on(s, p, "cell", sheet)?.unwrap_or(s.doc()?.selection.active); - let Some(h) = s.doc()?.wb.sheet(sheet).and_then(|sh| sh.hyperlinks.get(&at)) else { + let Some(h) = crate::links::cell_link(&s.doc()?.wb, sheet, at) else { return Err(EngineError::Other("There's no hyperlink in this cell.".into())); }; - h.target.clone() + h.target } }; match crate::links::classify(&target) { diff --git a/crates/engine/src/cmd/inspect.rs b/crates/engine/src/cmd/inspect.rs index e91a269fb..d6646743d 100644 --- a/crates/engine/src/cmd/inspect.rs +++ b/crates/engine/src/cmd/inspect.rs @@ -136,7 +136,7 @@ fn cell_get(s: &mut Session, p: &Json) -> Result { "style": style, "merge": sh.merge_at(c).map(|m| m.a1()), "comment": sh.comments.get(&c), - "hyperlink": sh.hyperlinks.get(&c), + "hyperlink": crate::links::cell_link(&d.wb, sheet, c), "python": cell.and_then(|x| x.py.as_deref()).map(|py| json!({ "code": py.code, "output": if py.object { "object" } else { "value" }, diff --git a/crates/engine/src/links.rs b/crates/engine/src/links.rs index 4c2318f07..9497de4ef 100644 --- a/crates/engine/src/links.rs +++ b/crates/engine/src/links.rs @@ -9,7 +9,9 @@ //! external addresses; only the host, after showing the address and getting OK from the user, //! opens one through [`crate::Session::open_confirmed_link`], which no command reaches. -use gridcraft_core::RangeRef; +use gridcraft_core::{CellRef, RangeRef}; +use gridcraft_formula::Expr; +use gridcraft_model::{Hyperlink, Workbook}; use serde_json::{Value as Json, json}; use crate::{EngineError, Result, Session, UiRequest}; @@ -86,6 +88,41 @@ pub fn classify(target: &str) -> LinkKind { } } +/// The link of a cell: the one stored with it, or, for a cell whose formula is `HYPERLINK(target, …)`, +/// the target that formula currently evaluates to. A scheme-less web address (`google.com`) is +/// opened over `https`, as Excel does. +pub fn cell_link(wb: &Workbook, sheet: usize, at: CellRef) -> Option { + let sh = wb.sheet(sheet)?; + if let Some(h) = sh.hyperlinks.get(&at) { + return Some(h.clone()); + } + let expr = sh.cell(at)?.formula.as_ref()?.expr()?; + let Expr::Call(name, args) = &expr else { return None }; + if name != "HYPERLINK" { + return None; + } + let value = gridcraft_calc::evaluate_expr(wb, sheet, at, args.first()?); + let target = value.display().trim().to_string(); + if target.is_empty() || matches!(value, gridcraft_core::Value::Error(_)) { + return None; + } + let target = if looks_like_web_address(&target) && wb.name(&target, sheet).is_none() { format!("https://{target}") } else { target }; + let external = !matches!(classify(&target), LinkKind::Internal(_)); + Some(Hyperlink { target, tooltip: None, external }) +} + +fn looks_like_web_address(t: &str) -> bool { + if t.contains(|c: char| c.is_whitespace() || matches!(c, '\\' | '!' | '#' | ':')) { + return false; + } + let host = t.split('/').next().unwrap_or(t); + let Some((_, tld)) = host.rsplit_once('.') else { return false }; + tld.len() >= 2 + && tld.chars().all(|c| c.is_ascii_alphabetic()) + && !["xlsx", "xlsm", "xlsb", "xls", "csv", "txt", "pdf", "doc", "docx"].contains(&tld.to_ascii_lowercase().as_str()) + && RangeRef::parse(t).is_none() +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 785e68f6b..7b25f7af6 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -7657,3 +7657,18 @@ fn history_charges_the_storage_of_empty_comment_replies() { // 500 replies of no text are still 500 elements. assert!(crate::sheet_text_bytes(&sheet) >= 500 * std::mem::size_of::<(String, String)>()); } + +#[test] +fn hyperlink_function_makes_a_cell_link() { + let mut s = s(); + s.link_policy = crate::links::LinkPolicy::Allow; + s.execute("cell.set", json!({"cell": "A1", "input": "https://example.com/x"})).unwrap(); + s.execute("cell.set", json!({"cell": "B2", "input": "=HYPERLINK(A1,\"Go\")"})).unwrap(); + s.execute("cell.set", json!({"cell": "C3", "input": "=HYPERLINK(\"google.com\")"})).unwrap(); + s.take_ui_requests(); + s.execute("link.open", json!({"cell": "B2"})).unwrap(); + assert_eq!(s.take_ui_requests(), vec![crate::UiRequest::OpenUrl("https://example.com/x".into())]); + s.execute("link.open", json!({"cell": "C3"})).unwrap(); + assert_eq!(s.take_ui_requests(), vec![crate::UiRequest::OpenUrl("https://google.com".into())]); + assert!(s.execute("link.open", json!({"cell": "A1"})).is_err()); +} diff --git a/crates/ui-egui/src/grid/interact.rs b/crates/ui-egui/src/grid/interact.rs index f0ab7bc8e..e5fe41f53 100644 --- a/crates/ui-egui/src/grid/interact.rs +++ b/crates/ui-egui/src/grid/interact.rs @@ -528,7 +528,7 @@ fn handle_press(app: &mut SheetApp, input: &InteractionInput<'_>) { } } else if mods.command { // Ctrl+click (without Alt) on a hyperlink's text follows it instead of adding the cell to the selection. - if let Some(h) = sh.hyperlinks.get(&c).cloned() + if let Some(h) = gridcraft_engine::links::cell_link(wb, wb.active_sheet(), c) && acts && !mods.alt && p.x < geo.cell_rect(sh, c).left() + geo.cell_rect(sh, c).width() * 0.8 @@ -545,7 +545,7 @@ fn handle_press(app: &mut SheetApp, input: &InteractionInput<'_>) { let _ = app.run("cell.toggleCheckbox", json!({"cell": c.a1()})); } // A click on a hyperlink's text follows it (like Excel); elsewhere in the cell selects. - if let Some(h) = sh.hyperlinks.get(&c).cloned() + if let Some(h) = gridcraft_engine::links::cell_link(wb, wb.active_sheet(), c) && acts && !mods.any() { diff --git a/crates/ui-egui/src/grid/show.rs b/crates/ui-egui/src/grid/show.rs index 713c2d51c..13839f1b8 100644 --- a/crates/ui-egui/src/grid/show.rs +++ b/crates/ui-egui/src/grid/show.rs @@ -770,7 +770,7 @@ pub(crate) fn paint_overlays(input: OverlayInput<'_>) { ); } // Hyperlink tooltip. - if let Some(h) = hover.and_then(|c| sh.hyperlinks.get(&c)) + if let Some(h) = hover.and_then(|c| gridcraft_engine::links::cell_link(wb, si, c)) && app.editor.is_none() { let tip = h.tooltip.clone().unwrap_or_else(|| format!("{}\nClick once to follow. Click and hold to select this cell.", h.target)); From def333fe4287bac6bdf7f84a0a56738ab201c920 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:56:52 +0700 Subject: [PATCH 5/6] #2230: HYPERLINK targets with a query, fragment or port open over https; a table name stays internal; a click resolves the link after committing an edit --- crates/engine/src/links.rs | 15 ++++++++++++--- crates/engine/src/tests.rs | 16 ++++++++++++++++ crates/ui-egui/src/grid/interact.rs | 11 +++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/links.rs b/crates/engine/src/links.rs index 9497de4ef..2b26c925b 100644 --- a/crates/engine/src/links.rs +++ b/crates/engine/src/links.rs @@ -106,16 +106,25 @@ pub fn cell_link(wb: &Workbook, sheet: usize, at: CellRef) -> Option if target.is_empty() || matches!(value, gridcraft_core::Value::Error(_)) { return None; } - let target = if looks_like_web_address(&target) && wb.name(&target, sheet).is_none() { format!("https://{target}") } else { target }; + // a defined name or a table of that spelling (`sales.data`) stays an internal target + let internal_name = wb.name(&target, sheet).is_some() || wb.table(&target).is_some(); + let target = if looks_like_web_address(&target) && !internal_name { format!("https://{target}") } else { target }; let external = !matches!(classify(&target), LinkKind::Internal(_)); Some(Hyperlink { target, tooltip: None, external }) } fn looks_like_web_address(t: &str) -> bool { - if t.contains(|c: char| c.is_whitespace() || matches!(c, '\\' | '!' | '#' | ':')) { + if t.contains(|c: char| c.is_whitespace() || matches!(c, '\\' | '!')) { return false; } - let host = t.split('/').next().unwrap_or(t); + // the host ends at the path, query or fragment (`google.com/x`, `google.com?q=1`, `google.com#top`) + let host = t.split(['/', '?', '#']).next().unwrap_or(t); + // with an optional port (`example.com:8443`); any other colon is a scheme or a sheet reference + let host = match host.split_once(':') { + Some((h, port)) if !port.is_empty() && port.len() <= 5 && port.bytes().all(|b| b.is_ascii_digit()) => h, + Some(_) => return false, + None => host, + }; let Some((_, tld)) = host.rsplit_once('.') else { return false }; tld.len() >= 2 && tld.chars().all(|c| c.is_ascii_alphabetic()) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 8a0563417..41ce6c2a9 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -7943,6 +7943,22 @@ fn hyperlink_function_makes_a_cell_link() { s.execute("link.open", json!({"cell": "C3"})).unwrap(); assert_eq!(s.take_ui_requests(), vec![crate::UiRequest::OpenUrl("https://google.com".into())]); assert!(s.execute("link.open", json!({"cell": "A1"})).is_err()); + // a scheme-less address with a query, fragment or port opens over https too + for (cell, input, url) in [ + ("D1", "=HYPERLINK(\"google.com?q=rust\")", "https://google.com?q=rust"), + ("D2", "=HYPERLINK(\"google.com#results\")", "https://google.com#results"), + ("D3", "=HYPERLINK(\"example.com:8443/x\")", "https://example.com:8443/x"), + ] { + s.execute("cell.set", json!({"cell": cell, "input": input})).unwrap(); + s.execute("link.open", json!({"cell": cell})).unwrap(); + assert_eq!(s.take_ui_requests(), vec![crate::UiRequest::OpenUrl(url.into())], "{input}"); + } + // a table named like an address stays an internal target + s.execute("range.setValues", json!({"range": "F1:G2", "values": [["a", "b"], [1, 2]]})).unwrap(); + s.execute("insert.table", json!({"range": "F1:G2", "name": "sales.data"})).unwrap(); + s.execute("cell.set", json!({"cell": "D4", "input": "=HYPERLINK(\"sales.data\")"})).unwrap(); + let link = crate::links::cell_link(&s.doc().unwrap().wb, 0, gridcraft_core::CellRef::parse("D4").unwrap()).unwrap(); + assert_eq!(link.target, "sales.data"); } /// #1348: the selection a workbook opens with, and the one a sheet gets on its first visit, take diff --git a/crates/ui-egui/src/grid/interact.rs b/crates/ui-egui/src/grid/interact.rs index 257231a29..09564ec9e 100644 --- a/crates/ui-egui/src/grid/interact.rs +++ b/crates/ui-egui/src/grid/interact.rs @@ -400,6 +400,13 @@ fn handle_row_header_press(app: &mut SheetApp, input: &InteractionInput<'_>, p: } } +/// The link of cell `c` on the active sheet as the session holds it now: a click may have just +/// committed an edit the frame's workbook snapshot predates (a `HYPERLINK` target cell). +fn current_cell_link(app: &SheetApp, c: CellRef) -> Option { + let d = app.session.active()?; + gridcraft_engine::links::cell_link(&d.wb, d.wb.active_sheet(), c) +} + fn handle_press(app: &mut SheetApp, input: &InteractionInput<'_>) { let (geo, sh, wb, resp) = (input.geo, input.sheet, input.workbook, input.response); let (pos, mods, sel) = (input.position, input.modifiers, &input.selection); @@ -528,7 +535,7 @@ fn handle_press(app: &mut SheetApp, input: &InteractionInput<'_>) { } } else if mods.command { // Ctrl+click (without Alt) on a hyperlink's text follows it instead of adding the cell to the selection. - if let Some(h) = gridcraft_engine::links::cell_link(wb, wb.active_sheet(), c) + if let Some(h) = current_cell_link(app, c) && acts && !mods.alt && p.x < geo.cell_rect(sh, c).left() + geo.cell_rect(sh, c).width() * 0.8 @@ -545,7 +552,7 @@ fn handle_press(app: &mut SheetApp, input: &InteractionInput<'_>) { let _ = app.run("cell.toggleCheckbox", json!({"cell": c.a1()})); } // A click on a hyperlink's text follows it (like Excel); elsewhere in the cell selects. - if let Some(h) = gridcraft_engine::links::cell_link(wb, wb.active_sheet(), c) + if let Some(h) = current_cell_link(app, c) && acts && !mods.any() { From 91f9b870704600eaf6e2ccafb0d58c33192e549d Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:15:09 +0100 Subject: [PATCH 6/6] Resize Table keeps main's refusal over merged cells (Excel's behaviour); test follows --- crates/engine/src/cmd/extra/data.rs | 2 -- crates/engine/src/tests.rs | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/extra/data.rs b/crates/engine/src/cmd/extra/data.rs index 37f383642..cc4490e7f 100644 --- a/crates/engine/src/cmd/extra/data.rs +++ b/crates/engine/src/cmd/extra/data.rs @@ -93,8 +93,6 @@ pub(super) fn table_resize(s: &mut Session, p: &Json) -> Result { let t = sheet.tables.get_mut(ti).ok_or_else(|| bad("table", "gone"))?; t.columns = cols; t.range = r; - // A table can't hold merged cells: those it now covers are unmerged, as by Insert Table. - sheet.merges.retain(|m| !m.intersects(&r)); cx.structural = true; Ok(Json::Null) }) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 829b15368..c1668a003 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -8208,12 +8208,14 @@ fn tables_never_hold_merged_cells() { assert_eq!(merges(&s).len(), 3); s.execute("edit.redo", json!({})).unwrap(); - // Resizing a table over merged cells unmerges them too. + // Resizing a table over merged cells is refused, as in Excel; the merge stays. let mut s = base(); s.execute("insert.table", json!({"range": "A1:B4", "name": "T"})).unwrap(); s.execute("home.mergeCells", json!({"range": "C2:D2"})).unwrap(); + let e = s.execute("table.resize", json!({"table": "T", "range": "A1:C4"})).unwrap_err().to_string(); + assert!(e.contains("can't overlap merged cells"), "{e}"); + s.execute("home.unmergeCells", json!({"range": "C2:D2"})).unwrap(); s.execute("table.resize", json!({"table": "T", "range": "A1:C4"})).unwrap(); - assert!(merges(&s).is_empty()); // Merged cells pasted into a table arrive unmerged; elsewhere they stay merged. s.execute("home.mergeCells", json!({"range": "E2:F3"})).unwrap();