Skip to content

Commit 8b4b361

Browse files
Preserve selection within active search after deletion
When deleting the active session while a search filter is applied, select the next visible item from the filtered result (if any) before falling back to the first valid session. This keeps user context consistent during search and prevents unexpected jumps to unrelated conversations
1 parent d9210e6 commit 8b4b361

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/pages/IndependentPanel/App.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,32 @@ function App() {
323323
}
324324
// Only change active session if the deleted one was active
325325
if (sessionId === deletedId) {
326+
// When searching, prefer the next visible item in the filtered result
327+
const q = normalizeForSearch(debouncedQuery).trim()
328+
if (q) {
329+
const SEP = '\n—\n'
330+
const nextFiltered = updatedSessions.find((s) => {
331+
if (!s || !s.sessionId) return false
332+
const nameNorm = normalizeForSearch(s?.sessionName)
333+
let bodyNorm = ''
334+
if (Array.isArray(s?.conversationRecords)) {
335+
bodyNorm = s.conversationRecords
336+
.map(
337+
(r) =>
338+
`${normalizeForSearch(r?.question)} ${normalizeForSearch(
339+
r?.answer,
340+
)}`,
341+
)
342+
.join(SEP)
343+
}
344+
return nameNorm.includes(q) || bodyNorm.includes(q)
345+
})
346+
if (nextFiltered) {
347+
await setSessionIdSafe(nextFiltered.sessionId)
348+
return
349+
}
350+
}
351+
// Fallback to first valid item in full list
326352
const next = updatedSessions.find((s) => s && s.sessionId)
327353
if (next) {
328354
await setSessionIdSafe(next.sessionId)

0 commit comments

Comments
 (0)