Skip to content

Commit 87dc403

Browse files
committed
fix(tui): sort session picker by timestamp with frozen order while open
The session picker now sorts by actual time.updated timestamp when first opened, but freezes that order while the user is browsing. This prevents sessions from jumping around as activity updates arrive, while still showing the most recently active sessions at the top initially. Search results continue to sort dynamically since they come from the server already ordered.
1 parent cd7ec93 commit 87dc403

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,26 @@ export function DialogSessionList() {
109109
))
110110
}
111111

112+
const [frozenOrder, setFrozenOrder] = createSignal<string[]>()
113+
114+
function computeOrder(allSessions: ReturnType<typeof sessions>) {
115+
return allSessions
116+
.filter((x) => x.parentID === undefined)
117+
.toSorted((a, b) => b.time.updated - a.time.updated)
118+
.map((x) => x.id)
119+
}
120+
112121
const options = createMemo(() => {
113122
const today = new Date().toDateString()
114-
return sessions()
115-
.filter((x) => x.parentID === undefined)
116-
.toSorted((a, b) => {
117-
const updatedDay = new Date(b.time.updated).setHours(0, 0, 0, 0) - new Date(a.time.updated).setHours(0, 0, 0, 0)
118-
if (updatedDay !== 0) return updatedDay
119-
return b.time.created - a.time.created
120-
})
123+
const allSessions = sessions()
124+
const isSearching = searchResults() !== undefined
125+
const order = isSearching ? computeOrder(allSessions) : (frozenOrder() ?? computeOrder(allSessions))
126+
127+
const sessionMap = new Map(allSessions.filter((x) => x.parentID === undefined).map((x) => [x.id, x]))
128+
129+
return order
130+
.map((id) => sessionMap.get(id))
131+
.filter((x) => x !== undefined)
121132
.map((x) => {
122133
const workspace = x.workspaceID ? project.workspace.get(x.workspaceID) : undefined
123134

@@ -172,6 +183,7 @@ export function DialogSessionList() {
172183

173184
onMount(() => {
174185
dialog.setSize("large")
186+
setFrozenOrder(computeOrder(sessions()))
175187
})
176188

177189
return (

0 commit comments

Comments
 (0)