Skip to content

Commit 093075a

Browse files
author
Aleksandar Prokopec
committed
Fixes SI-4461.
No review.
1 parent 34fa132 commit 093075a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/library/scala/collection/mutable/ObservableBuffer.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,18 @@ trait ObservableBuffer[A] extends Buffer[A] with Publisher[Message[A] with Undoa
7070
def undo() { throw new UnsupportedOperationException("cannot undo") }
7171
})
7272
}
73+
74+
abstract override def insertAll(n: Int, elems: collection.Traversable[A]) {
75+
super.insertAll(n, elems)
76+
var curr = n - 1
77+
val msg = elems.foldLeft(new Script[A]() with Undoable {
78+
def undo() { throw new UnsupportedOperationException("cannot undo") }
79+
}) {
80+
case (msg, elem) =>
81+
curr += 1
82+
msg += Include(Index(curr), elem)
83+
}
84+
publish(msg)
85+
}
86+
7387
}

test/files/run/t4461.check

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ Include(End,3)
44
Include(End,4)
55
Include(End,5)
66
Include(End,6)
7-
Include(End,7)
7+
Include(End,7)
8+
Script([1] Include(Index(7),8), [2] Include(Index(8),9), [3] Include(Index(9),10))
9+
Include(Start,0)
10+
Script([1] Include(Index(0),-2), [2] Include(Index(1),-1))
11+
Remove(Index(0),-2)

test/files/run/t4461.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ object Test {
1515
buf ++= ArrayBuffer(3, 4) // works
1616
buf ++= List(5) // works
1717
buf ++= collection.immutable.Vector(6, 7) // works
18+
buf.insertAll(7, List(8, 9, 10))
19+
0 +=: buf
20+
List(-2, -1) ++=: buf
21+
buf remove 0
1822
}
1923
}

0 commit comments

Comments
 (0)