fix: details load once the cursor rests, and moving on cancels them
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
879b961ac5
commit
cd35a8acf4
2 files changed
+27
-9
No files matched your search
@@ -30,7 +30,8 @@ type groupsMsg struct {
|
||||
}
|
||||
|
||||
// A vault's, scope's or file's details beyond its listing load once a
|
||||
// session, the first time it's shown, and again with refresh.
|
||||
// session, when the cursor rests on it, and again with refresh. They're
|
||||
// extra: moving on cancels the load, and search never waits for them.
|
||||
type detailsState struct {
|
||||
attrs []provider.Attr
|
||||
err error
|
||||
@@ -38,6 +39,7 @@ type detailsState struct {
|
||||
}
|
||||
|
||||
type detailsMsg struct {
|
||||
req int
|
||||
key string
|
||||
attrs []provider.Attr
|
||||
err error
|
||||
@@ -211,14 +213,22 @@ func (m *Model) loadDetails(c provider.Container) tea.Cmd {
|
||||
if _, seen := m.details[key]; !ok || seen {
|
||||
return nil
|
||||
}
|
||||
m.details[key] = detailsState{loading: true}
|
||||
timeout := m.timeout
|
||||
return func() tea.Msg {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
attrs, err := d.Details(ctx, c)
|
||||
return detailsMsg{key: key, attrs: attrs, err: err}
|
||||
// One at a time: the previous one, if it's still loading, is
|
||||
// cancelled and forgotten, to load when it's shown again.
|
||||
for k, st := range m.details {
|
||||
if st.loading {
|
||||
delete(m.details, k)
|
||||
}
|
||||
}
|
||||
m.details[key] = detailsState{loading: true}
|
||||
ctx, req := m.begin(slotDetails)
|
||||
return m.settled(ctx, func() tea.Msg {
|
||||
attrs, err := d.Details(ctx, c)
|
||||
if ctx.Err() != nil {
|
||||
err = ctx.Err()
|
||||
}
|
||||
return detailsMsg{req: req, key: key, attrs: attrs, err: err}
|
||||
})
|
||||
}
|
||||
|
||||
// problemFields show why an account has nothing to show, wrapped to the
|
||||
|
||||
Reference in new issue
Block a user