Fix tab order restore with limited tabs

If the number of documents are greater than the user set "Tab Limit", then tab order restore was broken. The existing implementation did the simple thing:

// assume tab limit = 2
docList = [1, 2, 3]
// expected restore order = [2, 3]

register doc "1", // gets tab 0
register doc "2", // gets tab 1
register doc "3", // gets tab 0, replace 0 because its the lru doc

restored order = [3, 2] // incorrect

To fix this, we must do an additional pass over the tabs and restore the tabs to what the docList says. We can do this simply by calling setTabDocument for each document we have in the right order. To find the right order, instead of traversing the docList again we can just use m_registeredDocuments which stores the document in MRU order. So for the above case, the order is:

m_registeredDocument = [3, 2, 1]

We can just reverse iterate m_registeredDocuments and fix the tabs. But we can't just iterate it directly, we must first skip the documents that don't have tabs. We can find that by simply subtracting the number of tabs from m_registeredDocuments. This works because when saving session state we always put the documents that don't have tabs first and then we add the documents that have tabs.

Also add a test case for this so that it doesn't break again.

BUG: 495419 Signed-off-by: Waqar Ahmed waqar.17a@gmail.com

Merge request reports

Loading
Loading