mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-06 23:06:20 +01:00
notebook: handle duplicate mimetypes in list
This commit is contained in:
@@ -652,11 +652,13 @@ export class MimeTypeDisplayOrder {
|
||||
|
||||
// Get the other mimetypes that are before the chosenMimetype. Then, move
|
||||
// them after it, retaining order.
|
||||
const otherIndices = otherMimetypes.map(m => this.findIndex(m, chosenIndex)).filter(i => i !== -1);
|
||||
const uniqueIndicies = new Set(otherMimetypes.map(m => this.findIndex(m, chosenIndex)));
|
||||
uniqueIndicies.delete(-1);
|
||||
const otherIndices = Array.from(uniqueIndicies).sort();
|
||||
this.order.splice(chosenIndex + 1, 0, ...otherIndices.map(i => this.order[i]));
|
||||
|
||||
for (const i of otherIndices.sort((a, b) => b - a)) {
|
||||
this.order.splice(i, 1);
|
||||
for (let oi = otherIndices.length - 1; oi >= 0; oi--) {
|
||||
this.order.splice(otherIndices[oi], 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,6 +192,11 @@ suite('NotebookCommon', () => {
|
||||
// deletes multiple
|
||||
m.prioritize('text/plain', ['text/plain', 'text/html', Mimes.markdown]);
|
||||
assert.deepStrictEqual(m.toArray(), ['text/plain', 'text/html', Mimes.markdown, 'application/json']);
|
||||
|
||||
// handles multiple mimetypes, unknown mimetype
|
||||
const m2 = new MimeTypeDisplayOrder(['a', 'b']);
|
||||
m2.prioritize('b', ['a', 'b', 'a', 'q']);
|
||||
assert.deepStrictEqual(m2.toArray(), ['b', 'a']);
|
||||
});
|
||||
|
||||
test('sortMimeTypes glob', function () {
|
||||
|
||||
Reference in New Issue
Block a user