Commit 67dc5b26 authored by Sebastian Kaspari's avatar Sebastian Kaspari
Browse files

Issue #3432: SessionManager: Add restored tabs at the beginning of the list.

parent 2192b68c
......@@ -140,7 +140,7 @@ class LegacySessionManager(
addInternal(session, selected, engineSession, parent = parent, viaRestore = false)
}
@Suppress("LongParameterList")
@Suppress("LongParameterList", "ComplexMethod")
private fun addInternal(
session: Session,
selected: Boolean = false,
......@@ -160,7 +160,16 @@ class LegacySessionManager(
values.add(parentIndex + 1, session)
} else {
values.add(session)
if (viaRestore) {
// We always restore Sessions at the beginning of the list to pretend those sessions existed before
// we added any other sessions (e.g. coming from an Intent)
values.add(0, session)
if (selectedIndex != NO_SELECTION) {
selectedIndex++
}
} else {
values.add(session)
}
}
if (engineSession != null) {
......@@ -201,7 +210,7 @@ class LegacySessionManager(
return
}
snapshot.sessions.forEach {
snapshot.sessions.asReversed().forEach {
addInternal(
it.session,
engineSession = it.engineSession,
......
......@@ -367,9 +367,9 @@ class SessionManagerTest {
assertEquals(3, manager.size)
assertEquals("https://www.mozilla.org", manager.selectedSessionOrThrow.url)
assertEquals("https://www.mozilla.org", manager.sessions[0].url)
assertEquals("https://www.firefox.com", manager.sessions[1].url)
assertEquals("https://getpocket.com", manager.sessions[2].url)
assertEquals("https://getpocket.com", manager.sessions[0].url)
assertEquals("https://www.mozilla.org", manager.sessions[1].url)
assertEquals("https://www.firefox.com", manager.sessions[2].url)
verify(observer).onSessionsRestored()
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment