Skip to content

Commit a5cbad0

Browse files
authored
fix: removing stream selections (webtorrent#2952)
1 parent ac6a0e3 commit a5cbad0

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

lib/selections.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@ export class Selections {
2727
remove (item) {
2828
for (let i = 0; i < this._items.length; i++) {
2929
const existing = this._items[i]
30+
// we only remove stream selections when the `isStreamSelection` flag match, cast to boolean using !
31+
if (!existing.isStreamSelection !== !item.isStreamSelection) continue
32+
3033
if (existing.isStreamSelection) {
31-
if (item.isStreamSelection) {
32-
// If both are stream selections and they match, then we remove the first matching item, then we break the loop
33-
if (existing.from === item.from && existing.to === item.to) {
34-
this._items.splice(i, 1)
35-
// for stream selections, we only remove one item at a time
36-
// ergo we break the loop after removing the first matching item
37-
break
38-
}
39-
} else {
40-
// we only remove stream selections when the `isStreamSelection` flag is true and they match
41-
continue
34+
// If both are stream selections and they match, then we remove the first matching item, then we break the loop
35+
if (existing.from === item.from && existing.to === item.to) {
36+
this._items.splice(i, 1)
37+
// for stream selections, we only remove one item at a time
38+
// ergo we break the loop after removing the first matching item
39+
break
4240
}
4341
} else {
4442
if (isLowerIntersecting(item, existing)) {

0 commit comments

Comments
 (0)