From e8207288e554e3619dd0a8186e93b83047719bf1 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 19 Oct 2024 17:10:50 +0200 Subject: [PATCH] Refold updated patch only if the patch was already folded (#19462) Release Notes: - N/A --- crates/assistant/src/assistant_panel.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 91a8eb77285aa876b4aae4c7a271f16e3ca4fa03..dea0cd85968a321098d2ba4bc254b7b05a2ee4a4 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -2219,6 +2219,7 @@ impl ContextEditor { merge_adjacent: false, }; + let should_refold; if let Some(state) = self.patches.get_mut(&range) { replaced_blocks.insert(state.footer_block_id, render_block); if let Some(editor_state) = &state.editor { @@ -2233,6 +2234,9 @@ impl ContextEditor { }); } } + + should_refold = + snapshot.intersects_fold(patch_start.to_offset(&snapshot.buffer_snapshot)); } else { let block_ids = editor.insert_blocks( [BlockProperties { @@ -2266,10 +2270,14 @@ impl ContextEditor { update_task: None, }, ); + + should_refold = true; } - editor.unfold_ranges([patch_start..patch_end], true, false, cx); - editor.fold_ranges([(patch_start..patch_end, header_placeholder)], false, cx); + if should_refold { + editor.unfold_ranges([patch_start..patch_end], true, false, cx); + editor.fold_ranges([(patch_start..patch_end, header_placeholder)], false, cx); + } } editor.remove_creases(removed_crease_ids, cx);