Skip to content

Commit 4516612

Browse files
yungthaisindrets
andauthored
feat(actions): added select_{prev|next}_commit (#512)
Co-authored-by: Sindre T. Strøm <[email protected]>
1 parent 52e6cb2 commit 4516612

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

doc/diffview.txt

+12-2
Original file line numberDiff line numberDiff line change
@@ -1165,12 +1165,12 @@ select_entry *diffview-actions-select_entry*
11651165
multiple files, this will collapse or open the entry. In the option
11661166
panel this will interact with the option under the cursor.
11671167

1168-
select_next_entry *diffview-actions-select_next_entry*
1168+
[count] select_next_entry *diffview-actions-select_next_entry*
11691169
Contexts: `view`, `file_panel`, `file_history_panel`
11701170

11711171
Select the entry following the subject.
11721172

1173-
select_prev_entry *diffview-actions-select_prev_entry*
1173+
[count] select_prev_entry *diffview-actions-select_prev_entry*
11741174
Contexts: `view`, `file_panel`, `file_history_panel`
11751175

11761176
Select the entry preceding the subject.
@@ -1185,6 +1185,16 @@ select_last_entry *diffview-actions-select_last_en
11851185

11861186
Select the last entry.
11871187

1188+
[count] select_next_commit *diffview-actions-select_next_commit*
1189+
Contexts: `file_history_view`, `file_history_panel`
1190+
1191+
Select the commit following the subject.
1192+
1193+
[count] select_prev_commit *diffview-actions-select_prev_commit*
1194+
Contexts: `file_history_view`, `file_history_panel`
1195+
1196+
Select the commit preceding the subject.
1197+
11881198
stage_all *diffview-actions-stage_all*
11891199
Contexts: `diff_view`, `file_panel`
11901200

lua/diffview/actions.lua

+2
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ local action_names = {
637637
"select_prev_entry",
638638
"select_first_entry",
639639
"select_last_entry",
640+
"select_next_commit",
641+
"select_prev_commit",
640642
"stage_all",
641643
"toggle_files",
642644
"toggle_flatten_dirs",

lua/diffview/scene/views/file_history/file_history_view.lua

+5
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,13 @@ FileHistoryView.set_file = async.void(function(self, file, focus)
170170
if self:file_safeguard() or not file then return end
171171

172172
local entry = self.panel:find_entry(file)
173+
local cur_entry = self.panel.cur_item[1]
173174

174175
if entry then
176+
if cur_entry and entry ~= cur_entry then
177+
self.panel:set_entry_fold(cur_entry, false)
178+
end
179+
175180
self.panel:set_cur_item({ entry, file })
176181
self.panel:highlight_item(file)
177182
self.nulled = false

lua/diffview/scene/views/file_history/listeners.lua

+20
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ return function(view)
7171
view:set_file(entry.files[#entry.files])
7272
end
7373
end,
74+
select_next_commit = function()
75+
local cur_entry = view.panel.cur_item[1]
76+
if not cur_entry then return end
77+
local entry_idx = utils.vec_indexof(view.panel.entries, cur_entry)
78+
if entry_idx == -1 then return end
79+
80+
local next_idx = (entry_idx + vim.v.count1 - 1) % #view.panel.entries + 1
81+
local next_entry = view.panel.entries[next_idx]
82+
view:set_file(next_entry.files[1])
83+
end,
84+
select_prev_commit = function()
85+
local cur_entry = view.panel.cur_item[1]
86+
if not cur_entry then return end
87+
local entry_idx = utils.vec_indexof(view.panel.entries, cur_entry)
88+
if entry_idx == -1 then return end
89+
90+
local next_idx = (entry_idx - vim.v.count1 - 1) % #view.panel.entries + 1
91+
local next_entry = view.panel.entries[next_idx]
92+
view:set_file(next_entry.files[1])
93+
end,
7494
next_entry = function()
7595
view.panel:highlight_next_file()
7696
end,

0 commit comments

Comments
 (0)