Current sorting algorithm doesn't distinct between tabs with equal URLs.
// Current sorting algorithm
openTabs = [
{id: 1004, name: 'example1', url: 'example'},
{id: 1005, name: 'example2', url: 'example'},
{id: 1006, name: 'another', url: 'another'} // active tab
]
savedTabs = [
{id: 2004, name: 'example1', url: 'example'},
{id: 2006, name: 'another', url: 'active'},
{id: 2005, name: 'example2', url: 'example'}, // was active
]
// The regisry is initialized incrorrectly
registry = [
{id: 1005, name: 'example2', url: 'example'}, // fail (example1 and example2 should be swapped)
{id: 1004, name: 'example1', url: 'example'},
{id: 1006, name: 'another', url: 'active'},
]
The new sorting algorithm will calculate and use creationOrderId to sort tabs.
Creation order is an order in which the tab with specific URL was created.
The id is added to open and saved tabs before sorting.
Here is the fixed example:
openTabs = [
{id: 1004, name: 'example1', url: 'example', creationOrderId: 1},
{id: 1005, name: 'example2', url: 'example', creationOrderId: 2},
{id: 1006, name: 'another', url: 'another', creationOrderId: 1} // active tab
]
savedTabs = [
{id: 2004, name: 'example1', url: 'example', creationOrderId: 1},
{id: 2006, name: 'another', url: 'active', creationOrderId: 1},
{id: 2005, name: 'example2', url: 'example', creationOrderId: 2}, // was active
]
// Note that creationOrderIds are equal for savedTabs and openTabs.
// During the sorting we will use URL and creationOrderId.
// The regisry is initialized correctly
registry = [
{id: 1004, name: 'example1', url: 'example', creationOrderId: 1},
{id: 1005, name: 'example2', url: 'example', creationOrderId: 2}, // correct
{id: 1006, name: 'another', url: 'active', creationOrderId: 1},
]
Problem
Current sorting algorithm doesn't distinct between tabs with equal URLs.
The new sorting algorithm will calculate and use creationOrderId to sort tabs. Creation order is an order in which the tab with specific URL was created. The id is added to open and saved tabs before sorting. Here is the fixed example: