Library: keep the place after removing a title

The list is reloaded after a removal and the selection follows the
selected title by id; the removed title is gone, so it fell back to the
top. Now a title that has left the library hands its row to the one that
moved up into it (or the new last one). A title that is only filtered out
still starts the list from the top.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019reK4DUGYqDUjniWYJvwUW
This commit is contained in:
2026-10-21 12:35:49 +02:00
co-authored by Claude Opus 5.5
parent b49bb1ef31
commit 12e5d5aa33
3 changed files with 68 additions and 2 deletions
+18 -2
View File
@@ -391,9 +391,9 @@ func (v *libraryView) render() {
}
func (v *libraryView) renderPane(p *libPane) {
selID := -1
selID, prevRow := -1, 0
if r, _ := p.table.GetSelection(); r >= 1 && r <= len(p.shown) {
selID = p.shown[r-1].id
selID, prevRow = p.shown[r-1].id, r
}
p.shown = filterItems(p.all, p.filter, p.text, p.attr)
@@ -408,6 +408,13 @@ func (v *libraryView) renderPane(p *libPane) {
selRow = i + 1
}
}
if selRow == 0 && selID != -1 && !containsItem(p.all, selID) {
// The selected title is gone from the library (removed): stay at its
// place, on the title that moved up into it (or the new last one),
// instead of jumping to the top. A title that is only filtered out
// still starts the list from the top.
selRow = min(prevRow, len(p.shown))
}
placeholder := "Nothing matches the filter"
switch {
case p.err != nil && !p.loaded:
@@ -437,6 +444,15 @@ func (v *libraryView) renderPane(p *libPane) {
p.table.SetTitle(title + " ")
}
func containsItem(items []libItem, id int) bool {
for _, it := range items {
if it.id == id {
return true
}
}
return false
}
func (v *libraryView) renderDetails() {
if it, ok := v.selected(); ok {
v.details.Show(it.details, it.cover)