jjui icon indicating copy to clipboard operation
jjui copied to clipboard

Search and filetree in diffs

Open abourget opened this issue 1 month ago • 5 comments

Is your feature request related to a problem? Please describe.

I need to be able to search diffs, and jump to files in a diff, to study it fast

I use gitk usually for this. So only missing things here:

  • being able to jump to a file when viewing a diff,
  • being able to search the diff, to find the chunk of code I want to understand better

Describe the solution you'd like

I think hitting d to view a diff is great, but then, in there, I'd like to have 4 more shortcuts:

  • / to be able to search inside the diff view.. just plain text.. and go there
  • N and n to go back and forth the matches, like in vim (why not g and G, end/home, like vim)
  • t that would pop up a fuzzy search, to get down to the file I want.. and also see quickly which files are int he diff when the patches are long.
    • I could already jump to files that I know the name with the search.. but seeing the list is often useful, to see the sort of broadness of patches, the impact of it too.

Describe alternatives you've considered

Right now, to study the diffs, I need to have this command:

diffnav has a great t shortcut, with fuzzy search. See the demo here: https://github.com/dlvhdr/diffnav It looks like GitHub's t.. It's missing the / search though, making diffnav not ideal either, and it brings you outside, in a less familiar place.

Here's my command to get to it:

[custom_commands]
"diffnav from checked" = { args = ["util", "exec", "--", "bash", "-c", """
jj diff --from $checked_commit_ids --to $change_id --color=always --summary --git | diffnav
"""], show = "interactive" }

(allows me to diff between separate commits by choosing one.. that I haven't found a way to do natively in jjui and I do that all the time in gitk).

abourget avatar Nov 12 '25 22:11 abourget

very rough first thought on this:

  • right now diff view is simply rendering the content of a diff
  • hence it's losing the pager's built-in functionalities like /, n/N, g/G
  • a possible solution is to spawn a new view and let user's pager (like delta) take over, jjui only intercepts certain keys like esc to quit https://github.com/idursun/jjui/blob/1356d11a3fc193f9ed142028010cbef34b128ee3/internal/ui/diff/diff.go#L54-L65

baggiiiie avatar Nov 13 '25 12:11 baggiiiie

Yes, this is something that I always wanted (tend to use vim keys in pager -- and they just did not work inside jjui diffview).

I like the idea of not having our own pager, and let whatever the user has configured as jj pager.

Maybe there's a good reason why jjui has its own diffview. But I'm +1 on letting pagers do their job (like searching or using diffnav, in this case)

EDIT: oh now I remember the reason why I believe we have a custom pager, and that is the preview pane. Not sure if we could embed another tui in the preview pane, for example.

vic avatar Nov 13 '25 13:11 vic

but navigating the file tree would quickly change the contents that is viewed, would it kill less and restart it all the time?

abourget avatar Nov 13 '25 16:11 abourget

The problem with shelling out to a pager is that if the diff is small then the pager is not used therefore the diff will show but then will immediately return to jjui without user seeing anything. I use the internal diff view to be much faster way of having a peek at the diff. For cases where you need to investigate the diff, then you can use a custom command to show the diff in a pager in the way you like. I believe you can pass a config argument to jj to use a pager of your choice.

idursun avatar Nov 15 '25 20:11 idursun

The current preview panel is just missing /, n/N and g/G to be really useful. It's a pager, it does its job well and is well integrated. I wouldn't shell out to a third-party process, the integration would be more complex, wouldn't it?

then, a / search in that same preview would be already pretty good: if the panel is open, it could search within the panel (with all files if none are selected, or the selected file, again in the preview panel, and fallback to the search in the revsets).

  • Now there would be conflict with n for search next/previous.. unsure what to do with that. I often have the reflect to hit n after a / search, and start creating changesets.. so maybe search becomes a mode, you hit /, you need to get out of it with esc ?!
    • And then, when you have a search mode, perhaps the t key can do a fuzzy search on the list of files that are already present when you hit l to open the filelist on a commit?

abourget avatar Nov 20 '25 13:11 abourget