sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.57k stars 101 forks source link

[feature] Add actions for selecting first / last entry #421

Closed emmanueltouzery closed 3 weeks ago

emmanueltouzery commented 9 months ago

Hello, I use diffview in a way that I select the current file when opening, using --selected-file=. This works great for me.

However sometimes I want to use diffview to review all the changes. So, I open the diff view, the current file selected, but I'd like to jump to the first file to go through all the files one by one and be sure I didn't miss any of them. I don't know a way to do that... I know of:

lua require'diffview.config'.actions.select_next_entry()

And the equivalent for the previous entry, but how could I jump to the first entry with a single keyboard shortcut? Thank you!

emmanueltouzery commented 9 months ago

I found a way to achieve that..

      require('diffview').setup {
        keymaps = {
          view = {
            ["F"] = function() -- jump to first file in the diff
              local view = require'diffview.lib'.get_current_view()
              view:set_file(view.panel.files[1], false, true)
            end,
          },

works great!

EDIT this is better:

      require('diffview').setup {
        keymaps = {
          view = {
            ["F"] = function() -- jump to first file in the diff
              local view = require'diffview.lib'.get_current_view()
                view:set_file(view.panel:ordered_file_list()[1], false, true)
            end,
          },
sindrets commented 9 months ago

Cool that found a solution! But I think it would still be valuable to have actions for select_[first|last]_entry, so I'll keep the issue open.

yungthai commented 3 weeks ago

@sindrets I'll have a go adding this feature.

Thank you for creating a very useful plugin.