Skip to content
Closed
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
25 changes: 23 additions & 2 deletions internal/ui/revisions/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Model struct {
matchedStyle lipgloss.Style
ensureCursorView bool
requestInFlight bool
pendingRefresh bool
}

type revisionsMsg struct {
Expand Down Expand Up @@ -347,15 +348,27 @@ func (m *Model) internalUpdate(msg tea.Msg) tea.Cmd {
m.hasMore = msg.hasMore
m.isLoading = m.hasMore && len(m.offScreenRows) > 0

streamDone := false
if m.hasMore {
// keep requesting rows until we reach the initial load count or the current cursor position
lastRowIndex := m.displayContextRenderer.GetLastRowIndex()
if len(m.offScreenRows) < m.cursor+1 || len(m.offScreenRows) < lastRowIndex+1 {
return m.requestMoreRows(msg.tag)
}
} else if m.streamer != nil {
m.streamer.Close()
// Have enough rows — close the stream so the jj process doesn't linger
if m.streamer != nil {
m.streamer.Close()
m.streamer = nil
}
streamDone = true
} else {
if m.streamer != nil {
m.streamer.Close()
m.streamer = nil
}
streamDone = true
}
Comment on lines +358 to 370
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both of the branches are doing the same thing, so else branch is redundant here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 This PR in general was an off-cycle investigation w/ claude, and I clearly didn't look at the changes closely enough before submitting the PR.

m.isLoading = false

currentSelectedRevision := m.SelectedRevision()
m.rows = m.offScreenRows
Expand All @@ -378,6 +391,10 @@ func (m *Model) internalUpdate(msg tea.Msg) tea.Cmd {
return common.UpdateRevisionsSuccessMsg{}
})
}
if streamDone && m.pendingRefresh {
m.pendingRefresh = false
cmds = append(cmds, common.RefreshAndKeepSelections)
}
Comment on lines +394 to +397
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not debouncing but queueing the next refresh.

I don't see how this is helping with your situation. If a refresh is going on (say it takes 5 seconds each) and if you focus back 3 seconds later, instead of cancelling the ongoing one and saving 2 seconds, now you wait total of 10 seconds. Current implementation would settle in 8 seconds.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debouncing is in the change to the refresh function. However, if we only included that change, then we'd lose out on trailing updates. That said, maybe I've misunderstood the tea model, and this will still block the UI updates, as you say.

return tea.Batch(cmds...)
}

Expand Down Expand Up @@ -498,6 +515,10 @@ func (m *Model) startBookmarkSet() tea.Cmd {
}

func (m *Model) refresh(intent intents.Refresh) tea.Cmd {
if config.Current.Revisions.LogBatching && m.isLoading {
m.pendingRefresh = true
return nil
}
if !intent.KeepSelections {
m.context.ClearCheckedItems(reflect.TypeFor[appContext.SelectedRevision]())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
}
return nil
case tea.FocusMsg:
return common.RefreshAndKeepSelections
return func() tea.Msg { return common.AutoRefreshMsg{} }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't make sense to me. Why using auto refresh message here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this change was to take advantage of the AutoRefreshMsg behavior in revisions.go that only triggers a RefreshAndKeepSelections if the oplog has changed since the last update. Perhaps it would be better to put that check directly into the RefreshMsg handler instead?

case tea.MouseReleaseMsg:
if m.splitActive {
m.splitActive = false
Expand Down