Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ui/page/values_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ func (vc *ValuesController) ResetState() {
vc.State.PendingFocusKey = ""
vc.State.PendingFocusHighlight = false
vc.State.FocusHighlightAttempts = 0
vc.State.AwaitingFocusRestore = false
vc.State.FocusedRow = 0
vc.State.FocusedCol = 0
vc.State.CollapsedKeys = nil
Expand Down Expand Up @@ -852,6 +853,11 @@ func (vc *ValuesController) loadSavedCellFocusAsync() {
return
}

// Suppress focus persistence until pollChartUIState applies the result, so
// the section-advance default focus can't race a save onto disk ahead of
// the real restored key.
vc.State.AwaitingFocusRestore = true

appState := vc.AppState

vc.ChartUIStateRunner.RunWithTimeout(config.ChartUIStateLoadOperation, func(ctx context.Context) (chartUIStateResult, error) {
Expand Down Expand Up @@ -879,6 +885,8 @@ func (vc *ValuesController) pollChartUIState() {
if res.Err != nil {
slog.Error("load chart ui state", "error", res.Err)

vc.State.AwaitingFocusRestore = false

return
}

Expand All @@ -887,6 +895,8 @@ func (vc *ValuesController) pollChartUIState() {
return
}

vc.State.AwaitingFocusRestore = false

if !res.Value.found {
return
}
Expand Down
8 changes: 6 additions & 2 deletions ui/page/values_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ func (p *ValuesPage) Layout(gtx layout.Context) layout.Dimensions {
}
}

p.State.PendingFocusKey = ""
// Keep the key for re-resolution on later frames while a highlight is pending
if !p.State.PendingFocusHighlight {
p.State.PendingFocusKey = ""
}
}

// Clamp focused row to stay within filtered bounds.
Expand Down Expand Up @@ -542,6 +545,7 @@ func (p *ValuesPage) Layout(gtx layout.Context) layout.Dimensions {
if done {
p.State.PendingFocusHighlight = false
p.State.FocusHighlightAttempts = 0
p.State.PendingFocusKey = ""

// Treat the restored focus as already-synced so we don't
// immediately re-persist it back to disk on the next
Expand All @@ -553,7 +557,7 @@ func (p *ValuesPage) Layout(gtx layout.Context) layout.Dimensions {
p.lastFocusedRow = p.State.FocusedRow
p.lastFocusedCol = p.State.FocusedCol

if p.OnCellFocusChanged != nil {
if p.OnCellFocusChanged != nil && !p.State.AwaitingFocusRestore {
p.OnCellFocusChanged(p.State.FocusedEntryKey(), p.State.FocusedCol)
}
}
Expand Down
4 changes: 4 additions & 0 deletions ui/state/values_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ type ValuesPageState struct {
PendingFocusHighlight bool
FocusHighlightAttempts int

// AwaitingFocusRestore is true between a chart open and the moment its
// persisted UI state is applied (or found absent).
AwaitingFocusRestore bool

// CollapsedKeys is the effective set of section flat keys whose descendants
// are hidden on the values page. Map for O(1) ancestor-prefix checks during
// filter rebuild. During a search the page may auto-uncollapse ancestors of
Expand Down
Loading