Fix multiple cursors inserting repeated text in multibuffers
This commit is contained in:
parent
6c57fcf9be
commit
68de51ba8a
2 changed files with 15 additions and 7 deletions
|
@ -9801,7 +9801,17 @@ mod tests {
|
|||
#[gpui::test]
|
||||
fn test_editing_overlapping_excerpts(cx: &mut gpui::MutableAppContext) {
|
||||
cx.set_global(Settings::test(cx));
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(3, 4, 'a'), cx));
|
||||
let buffer = cx.add_model(|cx| {
|
||||
Buffer::new(
|
||||
0,
|
||||
indoc! {"
|
||||
aaaa
|
||||
bbbb
|
||||
cccc"},
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
let multibuffer = cx.add_model(|cx| {
|
||||
let mut multibuffer = MultiBuffer::new(0);
|
||||
multibuffer.push_excerpts(
|
||||
|
|
|
@ -378,13 +378,11 @@ impl MultiBuffer {
|
|||
let mut insertions = Vec::new();
|
||||
let mut deletions = Vec::new();
|
||||
let empty_str: Arc<str> = "".into();
|
||||
while let Some((mut range, mut new_text, mut is_insertion)) = edits.next() {
|
||||
while let Some((next_range, next_new_text, next_is_insertion)) =
|
||||
edits.peek()
|
||||
{
|
||||
while let Some((mut range, new_text, mut is_insertion)) = edits.next() {
|
||||
while let Some((next_range, _, next_is_insertion)) = edits.peek() {
|
||||
if range.end >= next_range.start {
|
||||
range.end = cmp::max(next_range.end, range.end);
|
||||
new_text = format!("{new_text}{next_new_text}").into();
|
||||
|
||||
is_insertion |= *next_is_insertion;
|
||||
edits.next();
|
||||
} else {
|
||||
|
@ -395,7 +393,7 @@ impl MultiBuffer {
|
|||
if is_insertion {
|
||||
insertions.push((
|
||||
buffer.anchor_before(range.start)..buffer.anchor_before(range.end),
|
||||
new_text,
|
||||
new_text.clone(),
|
||||
));
|
||||
} else if !range.is_empty() {
|
||||
deletions.push((
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue