Posters wait while the selection moves quickly
On a terminal zoomed far out a poster is tens of thousands of cells, and redrawing it on every step of a held arrow key was more output than the terminal could draw (about 100 KB per step at 600x180), so the list lagged. A selection that changes again within 120 ms keeps the poster's place empty and shows the poster once it rests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019reK4DUGYqDUjniWYJvwUW
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"image"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
@@ -107,3 +110,30 @@ func TestDetailPaneFlowsAroundPoster(t *testing.T) {
|
||||
t.Error("a short pane must drop the poster")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPosterWaitsWhileTheSelectionMoves(t *testing.T) {
|
||||
a := newTestApp(t)
|
||||
img := image.NewRGBA(image.Rect(0, 0, 20, 30))
|
||||
a.coverCache.imgs["one"], a.coverCache.imgs["two"] = img, img
|
||||
ref := func(key string) coverRef {
|
||||
return coverRef{key: key, fetch: func(context.Context) ([]byte, error) { return nil, nil }}
|
||||
}
|
||||
d := newDetailPane(a)
|
||||
|
||||
d.Show(detailText{head: "One"}, ref("one"))
|
||||
if d.cover.img != img {
|
||||
t.Fatal("the first selection should show its poster at once")
|
||||
}
|
||||
d.Show(detailText{head: "Two"}, ref("two"))
|
||||
if d.cover.img != nil || !d.hasCover {
|
||||
t.Errorf("a quick move should keep the poster's place empty: img %v, hasCover %v", d.cover.img != nil, d.hasCover)
|
||||
}
|
||||
d.settle.Stop() // the test has no event loop to deliver it
|
||||
|
||||
// The same title again (a refresh) is not a move.
|
||||
d.lastShow = time.Now().Add(-time.Second)
|
||||
d.Show(detailText{head: "Two"}, ref("two"))
|
||||
if d.cover.img != img {
|
||||
t.Error("a selection at rest should show its poster")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user