From b86f8188d13cbd333ea5e44e19cc70504eba4daf Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 29 Mar 2023 16:31:12 +0200 Subject: [PATCH] Expand edit to end of the line when old/new row exceeds max expansion --- crates/editor/src/display_map/tab_map.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/editor/src/display_map/tab_map.rs b/crates/editor/src/display_map/tab_map.rs index 85f7acb2dd..7dd4d763e1 100644 --- a/crates/editor/src/display_map/tab_map.rs +++ b/crates/editor/src/display_map/tab_map.rs @@ -52,6 +52,28 @@ impl TabMap { if old_snapshot.tab_size == new_snapshot.tab_size { for suggestion_edit in &mut suggestion_edits { + let old_end = old_snapshot + .suggestion_snapshot + .to_point(suggestion_edit.old.end); + let old_end_row_len = old_snapshot.suggestion_snapshot.line_len(old_end.row()); + let old_end_row_exceeds_max_expansion = + old_end_row_len > old_snapshot.max_expansion_column; + let new_end = new_snapshot + .suggestion_snapshot + .to_point(suggestion_edit.new.end); + let new_end_row_len = new_snapshot.suggestion_snapshot.line_len(new_end.row()); + let new_end_row_exceeds_max_expansion = + new_end_row_len > new_snapshot.max_expansion_column; + if old_end_row_exceeds_max_expansion || new_end_row_exceeds_max_expansion { + suggestion_edit.old.end = old_snapshot + .suggestion_snapshot + .to_offset(SuggestionPoint::new(old_end.row(), old_end_row_len)); + suggestion_edit.new.end = new_snapshot + .suggestion_snapshot + .to_offset(SuggestionPoint::new(new_end.row(), new_end_row_len)); + continue; + } + let mut delta = 0; for chunk in old_snapshot.suggestion_snapshot.chunks( suggestion_edit.old.end..old_max_offset,