jjui icon indicating copy to clipboard operation
jjui copied to clipboard

Preview panel shows whole commit diff instead of selected file's diff when terminal regains focus

Open abourget opened this issue 4 weeks ago • 3 comments

When the terminal loses focus and regains it, the preview panel refreshes but displays the entire commit diff instead of the diff for the previously selected file. The file selection in the details list is preserved correctly, but the preview content is not in sync.

Root Cause:

Multiple components overwrite each other's selections during refresh operations. When tea.FocusMsg triggers RefreshMsg{KeepSelections: true}, both the revisions and details components process the refresh, but the revisions component calls updateSelection() which overwrites the file selection with a revision selection, causing the preview to use RevisionCommand instead of FileCommand.

Solution:

  1. Preview panel: Only refresh on RefreshMsg if we have a SelectedFile in context, preventing whole-diff display
  2. Revisions component: Add keepSelections flag to skip updateSelection() calls when KeepSelections: true
  3. Details component: Preserve cursor position (highlighted file) during refresh instead of defaulting to first file

This ensures that when the terminal regains focus, the file selection and preview content remain consistent, showing the correct file diff instead of the whole commit diff.


I'm relatively new to the codebase, let me know if this is the wrong way to approve the problem.

abourget avatar Nov 26 '25 23:11 abourget

Hey, thanks for the contribution!

Let me have a look at what's really happening.

idursun avatar Nov 26 '25 23:11 idursun

@abourget i am hopelessly bad to express code with words, just pushed a commit to demo my ideas

it addresses the immediate issue (though im not sure if any edge cases are missing), feel free to have a look and play around and apply to your fix!

baggiiiie avatar Nov 27 '25 11:11 baggiiiie

I found out the underlying issue is, when refreshed, revisions send and updateSelection command which is causing the preview window to update its contents.

I have verified that details is actually keeping the cursor at where it should be. (same for evolog as it is also affected by this).

The fix should be that the revisions should run updateSelection if currently selected item is not a revisions. This should be enough to fix the details view problem but not the evolog problem (as it is working with RevisionItem's because evolog item is just the same change id with a different commit id). Having said that though, I see evolog fix can be done in a separate PR.

I agree with @baggiiiie points as the fix is a little bit more convoluted then it should be. I haven't done any work on this, so I don't know yet how feasible the approach I described above, but I feel that it should be straightforward for fixing the details view issue.

idursun avatar Nov 27 '25 13:11 idursun

ok, I've rebased and pushed a new proposition, taking your feedback into account. What do you think?

This one keeps the current line height too, so better than the previous too.

abourget avatar Dec 05 '25 23:12 abourget