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]
|
#[gpui::test]
|
||||||
fn test_editing_overlapping_excerpts(cx: &mut gpui::MutableAppContext) {
|
fn test_editing_overlapping_excerpts(cx: &mut gpui::MutableAppContext) {
|
||||||
cx.set_global(Settings::test(cx));
|
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 multibuffer = cx.add_model(|cx| {
|
||||||
let mut multibuffer = MultiBuffer::new(0);
|
let mut multibuffer = MultiBuffer::new(0);
|
||||||
multibuffer.push_excerpts(
|
multibuffer.push_excerpts(
|
||||||
|
|
|
@ -378,13 +378,11 @@ impl MultiBuffer {
|
||||||
let mut insertions = Vec::new();
|
let mut insertions = Vec::new();
|
||||||
let mut deletions = Vec::new();
|
let mut deletions = Vec::new();
|
||||||
let empty_str: Arc<str> = "".into();
|
let empty_str: Arc<str> = "".into();
|
||||||
while let Some((mut range, mut new_text, mut is_insertion)) = edits.next() {
|
while let Some((mut range, new_text, mut is_insertion)) = edits.next() {
|
||||||
while let Some((next_range, next_new_text, next_is_insertion)) =
|
while let Some((next_range, _, next_is_insertion)) = edits.peek() {
|
||||||
edits.peek()
|
|
||||||
{
|
|
||||||
if range.end >= next_range.start {
|
if range.end >= next_range.start {
|
||||||
range.end = cmp::max(next_range.end, range.end);
|
range.end = cmp::max(next_range.end, range.end);
|
||||||
new_text = format!("{new_text}{next_new_text}").into();
|
|
||||||
is_insertion |= *next_is_insertion;
|
is_insertion |= *next_is_insertion;
|
||||||
edits.next();
|
edits.next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -395,7 +393,7 @@ impl MultiBuffer {
|
||||||
if is_insertion {
|
if is_insertion {
|
||||||
insertions.push((
|
insertions.push((
|
||||||
buffer.anchor_before(range.start)..buffer.anchor_before(range.end),
|
buffer.anchor_before(range.start)..buffer.anchor_before(range.end),
|
||||||
new_text,
|
new_text.clone(),
|
||||||
));
|
));
|
||||||
} else if !range.is_empty() {
|
} else if !range.is_empty() {
|
||||||
deletions.push((
|
deletions.push((
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue