Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions crates/editor/src/display_map/block_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,14 +1337,22 @@ impl BlockMap {
break;
}

let (delta_at_end, spacer_at_end) = determine_spacer(
&mut our_wrapper,
&mut companion_wrapper,
current_boundary,
current_range.end,
delta,
);
delta = delta_at_end;
let edit_for_current_boundary =
excerpt.patch.edit_for_old_position(current_boundary);

let spacer_at_end = if current_boundary == edit_for_current_boundary.old.end {
let (delta_at_end, spacer_at_end) = determine_spacer(
&mut our_wrapper,
&mut companion_wrapper,
current_boundary,
current_range.end,
delta,
);
delta = delta_at_end;
spacer_at_end
} else {
None
};

if let Some((wrap_row, mut height)) = spacer_at_start {
if let Some((_, additional_height)) = spacer_at_end {
Expand Down
130 changes: 130 additions & 0 deletions crates/editor/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3945,6 +3945,136 @@ mod tests {
assert_eq!(
lhs_pos.x, rhs_pos.x,
"LHS should have same horizontal scroll position as RHS after autoscroll"
)
}

#[gpui::test]
async fn test_edit_line_before_soft_wrapped_line_preceding_hunk(cx: &mut gpui::TestAppContext) {
use rope::Point;
use unindent::Unindent as _;

let (editor, mut cx) = init_test(cx, SoftWrap::EditorWidth).await;

let base_text = "
first line
aaaa bbbb cccc dddd eeee ffff
original
"
.unindent();

let current_text = "
first line
aaaa bbbb cccc dddd eeee ffff
modified
"
.unindent();

let (buffer, diff) = buffer_with_diff(&base_text, &current_text, &mut cx);

editor.update(cx, |editor, cx| {
let path = PathKey::for_buffer(&buffer, cx);
editor.set_excerpts_for_path(
path,
buffer.clone(),
vec![Point::new(0, 0)..buffer.read(cx).max_point()],
0,
diff.clone(),
cx,
);
});

cx.run_until_parked();

assert_split_content_with_widths(
&editor,
px(400.0),
px(200.0),
"
§ <no file>
§ -----
first line
aaaa bbbb cccc dddd eeee ffff
§ spacer
§ spacer
modified"
.unindent(),
"
§ <no file>
§ -----
first line
aaaa bbbb\x20
cccc dddd\x20
eeee ffff
original"
.unindent(),
&mut cx,
);

buffer.update(cx, |buffer, cx| {
buffer.edit(
[(Point::new(0, 0)..Point::new(0, 10), "edited first")],
None,
cx,
);
});

cx.run_until_parked();

assert_split_content_with_widths(
&editor,
px(400.0),
px(200.0),
"
§ <no file>
§ -----
edited first
aaaa bbbb cccc dddd eeee ffff
§ spacer
§ spacer
modified"
.unindent(),
"
§ <no file>
§ -----
first line
aaaa bbbb\x20
cccc dddd\x20
eeee ffff
original"
.unindent(),
&mut cx,
);

let buffer_snapshot = buffer.read_with(cx, |buffer, _| buffer.text_snapshot());
diff.update(cx, |diff, cx| {
diff.recalculate_diff_sync(&buffer_snapshot, cx);
});

cx.run_until_parked();

assert_split_content_with_widths(
&editor,
px(400.0),
px(200.0),
"
§ <no file>
§ -----
edited first
aaaa bbbb cccc dddd eeee ffff
§ spacer
§ spacer
modified"
.unindent(),
"
§ <no file>
§ -----
first line
aaaa bbbb\x20
cccc dddd\x20
eeee ffff
original"
.unindent(),
&mut cx,
);
}

Expand Down