Repository navigation
Conditional formats follow Clear Formats, Paste Special and the Format Painter #2926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,8 @@ pub use go_to::go_to_names; | |
| use go_to::go_to_special; | ||
| #[cfg(test)] | ||
| use go_to::{GO_TO_MAX_AREAS, GO_TO_RECENT, reference_parts}; | ||
| use paste_special::paste_special; | ||
| pub(crate) use paste_special::rewrite_all_formulas; | ||
| use paste_special::{copy_cond_formats, paste_special}; | ||
| use selection::{select_all, select_col, select_region, select_row, selection_move, selection_next, selection_set}; | ||
|
|
||
| pub fn specs() -> Vec<CommandSpec> { | ||
|
|
@@ -239,6 +239,10 @@ fn clear(s: &mut Session, p: &Json, what: &str) -> Result<Json> { | |
| }) | ||
| }; | ||
| edit(s, |cx| { | ||
| if matches!(what, "all" | "formats") { | ||
| // Conditional formats are formatting too, and may cover cells that hold nothing. | ||
| super::data::remove_cond_format_cells(&mut cx.sheet_mut(sheet)?.cond_formats, &ranges); | ||
| } | ||
| for r in &ranges { | ||
| let r = match cx.wb.sheet(sheet).and_then(|sh| sh.used_range()) { | ||
| Some(u) => match r.intersection(&u) { | ||
|
|
@@ -326,6 +330,7 @@ fn format_painter(s: &mut Session, p: &Json) -> Result<Json> { | |
| let Some((wb, sheet, src, sticky)) = s.format_painter.clone() else { return Err(EngineError::Other("Pick up a format first.".into())) }; | ||
| let dest_sheet = s.doc()?.wb.active_sheet(); | ||
| let same = std::sync::Arc::ptr_eq(&wb, &s.doc()?.wb) || s.doc()?.wb.styles == wb.styles; | ||
| let mut cf_formulas = false; | ||
| edit(s, |cx| { | ||
| let Some(src_sheet) = wb.sheet(sheet) else { return Ok(()) }; | ||
| let (h, w) = (src.height(), src.width()); | ||
|
|
@@ -394,9 +399,24 @@ fn format_painter(s: &mut Session, p: &Json) -> Result<Json> { | |
| cx.sheet_mut(dest_sheet)?.set_style(c, st); | ||
| cx.touch(dest_sheet, c); | ||
| } | ||
| // The painter lifts conditional formats along with the cell formats. | ||
| let mut tiles = Vec::new(); | ||
| for tr in 0..dest.height().div_ceil(h) { | ||
| for tc in 0..dest.width().div_ceil(w) { | ||
| let Some(origin) = dest.start.offset((tr * h) as i64, (tc * w) as i64) else { continue }; | ||
| let clip = RangeRef::new(origin, origin.offset_clamped(h as i64 - 1, w as i64 - 1)).intersection(&dest); | ||
| tiles.extend(clip.map(|clip| (origin, clip))); | ||
| } | ||
| } | ||
| cf_formulas = copy_cond_formats(cx.sheet_mut(dest_sheet)?, src_sheet, src, &tiles); | ||
|
Comment on lines
+402
to
+411
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unbounded tile count in Format Painter can hang or exhaust memory. The cell loop at Line 395 stops after 2,000,000 cells. The new tile loop has no bound. When the destination is the whole sheet (select all),
Apply a cap here. Skip the conditional-format copy when the tile count exceeds the cap. Then 🛡️ Proposed fix
|
||
| *cx.sel = crate::Selection::range(dest); | ||
| Ok(()) | ||
| })?; | ||
| // Rules with formulas from another workbook leave this one untrusted, as pasting them does. | ||
| if cf_formulas && !same { | ||
| let d = s.doc_mut()?; | ||
| d.trust = d.trust.receive(crate::Trust::FromFile); | ||
| } | ||
|
Comment on lines
+415
to
+419
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if !sticky { | ||
| s.format_painter = None; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear Formats and Clear All also remove conditional formats in filtered-out rows.
clearleaves filtered-out rows alone for every other effect. Comments (line 296), hyperlinks (line 299), merges (line 304) and cell styles all useskip. The new call at Line 244 passes the fullranges. A Clear Formats on a filtered selection therefore keeps the cell styles in hidden rows but drops their conditional formats.Remove conditional formats only from the rows that are not filtered. The helper below splits each range around the filtered rows.
🛠️ Proposed fix
Add this helper next to
filtered_rows: