Fix SortedList.values iteration and general dec lifecycle fixes
Fixes #4652
This commit is contained in:
@@ -104,4 +104,18 @@ describe('SortedList', () => {
|
||||
{ key: 10 }
|
||||
]);
|
||||
});
|
||||
describe('values', () => {
|
||||
it('should iterate correctly when list items change during iteration', () => {
|
||||
list.insert(1);
|
||||
list.insert(2);
|
||||
list.insert(3);
|
||||
list.insert(4);
|
||||
const visited: number[] = [];
|
||||
for (const item of list.values()) {
|
||||
visited.push(item);
|
||||
list.delete(item);
|
||||
}
|
||||
deepStrictEqual(visited, [1, 2, 3, 4]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,7 +89,8 @@ export class SortedList<T> {
|
||||
}
|
||||
|
||||
public values(): IterableIterator<T> {
|
||||
return this._array.values();
|
||||
// Duplicate the array to avoid issues when _array changes while iterating
|
||||
return [...this._array].values();
|
||||
}
|
||||
|
||||
private _search(key: number): number {
|
||||
|
||||
@@ -11,9 +11,9 @@ export class Marker implements IMarker {
|
||||
private static _nextId = 1;
|
||||
|
||||
public isDisposed: boolean = false;
|
||||
private _disposables: IDisposable[] = [];
|
||||
private readonly _disposables: IDisposable[] = [];
|
||||
|
||||
private _id: number = Marker._nextId++;
|
||||
private readonly _id: number = Marker._nextId++;
|
||||
public get id(): number { return this._id; }
|
||||
|
||||
private readonly _onDispose = this.register(new EventEmitter<void>());
|
||||
|
||||
@@ -35,12 +35,7 @@ export class DecorationService extends Disposable implements IDecorationService
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.register(toDisposable(() => {
|
||||
for (const d of this._decorations.values()) {
|
||||
this._onDecorationRemoved.fire(d);
|
||||
}
|
||||
this.reset();
|
||||
}));
|
||||
this.register(toDisposable(() => this.reset()));
|
||||
}
|
||||
|
||||
public registerDecoration(options: IDecorationOptions): IDecoration | undefined {
|
||||
@@ -92,13 +87,6 @@ export class DecorationService extends Disposable implements IDecorationService
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
for (const d of this._decorations.values()) {
|
||||
this._onDecorationRemoved.fire(d);
|
||||
}
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
|
||||
class Decoration extends Disposable implements IInternalDecoration {
|
||||
|
||||
Reference in New Issue
Block a user