Fix multibuffer chunk splitting at UTF-8 boundaries (#57641)
Don't panic when a diff transform boundary falls inside a multi-byte UTF-8 character. Round split points up to the next char boundary and advance past any transform boundaries skipped by that adjustment. Closes FR-16 Release Notes: - Fixed a crash when deleting words near inline diff boundaries containing multi-byte characters
This commit is contained in:
1 parent
57ae4da7d4
commit
56a932dc78
2 files changed
+51
-4
No files matched your search
@@ -1527,6 +1527,42 @@ async fn test_basic_diff_hunks(cx: &mut TestAppContext) {
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_text_for_range_with_diff_transform_boundary_inside_multibyte_character(cx: &mut App) {
|
||||
let buffer = cx.new(|cx| Buffer::local("タx", cx));
|
||||
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let mut snapshot = multibuffer.read(cx).snapshot(cx);
|
||||
|
||||
fn ascii_summary_with_byte_len(byte_len: usize) -> MBTextSummary {
|
||||
let text = "x".repeat(byte_len);
|
||||
MBTextSummary::from(TextSummary::from(text.as_str()))
|
||||
}
|
||||
|
||||
// FR-16 shown a diff transform boundary two bytes into the leading 'タ'.
|
||||
// Build that transform tree directly so this test stays focused on chunk iteration.
|
||||
let mut diff_transforms = SumTree::default();
|
||||
diff_transforms.push(
|
||||
DiffTransform::BufferContent {
|
||||
summary: ascii_summary_with_byte_len(2),
|
||||
inserted_hunk_info: None,
|
||||
},
|
||||
(),
|
||||
);
|
||||
diff_transforms.push(
|
||||
DiffTransform::BufferContent {
|
||||
summary: ascii_summary_with_byte_len("タx".len() - 2),
|
||||
inserted_hunk_info: None,
|
||||
},
|
||||
(),
|
||||
);
|
||||
snapshot.diff_transforms = diff_transforms;
|
||||
|
||||
let text = snapshot
|
||||
.text_for_range(MultiBufferOffset(0)..snapshot.len())
|
||||
.collect::<String>();
|
||||
assert_eq!(text, "タx");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_repeatedly_expand_a_diff_hunk(cx: &mut TestAppContext) {
|
||||
let text = indoc!(
|
||||
|
||||
Reference in new issue
Block a user