Skip to content

Commit 52e6cb2

Browse files
yungthaisindrets
andauthored
feat(actions): added select_{first|last}_entry (#510)
Co-authored-by: Sindre T. Strøm <[email protected]>
1 parent 3afa6a0 commit 52e6cb2

File tree

7 files changed

+54
-4
lines changed

7 files changed

+54
-4
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ require("diffview").setup({
276276
-- tabpage is a Diffview.
277277
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
278278
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
279+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
280+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
279281
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
280282
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
281283
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
@@ -341,6 +343,8 @@ require("diffview").setup({
341343
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
342344
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
343345
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
346+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
347+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
344348
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
345349
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
346350
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
@@ -365,9 +369,7 @@ require("diffview").setup({
365369
{ "n", "y", actions.copy_hash, { desc = "Copy the commit hash of the entry under the cursor" } },
366370
{ "n", "L", actions.open_commit_log, { desc = "Show commit details" } },
367371
{ "n", "X", actions.restore_entry, { desc = "Restore file to the state from the selected entry" } },
368-
{ "n", "zr", actions.open_fold, { desc = "Expand fold" } },
369372
{ "n", "zo", actions.open_fold, { desc = "Expand fold" } },
370-
{ "n", "zm", actions.close_fold, { desc = "Collapse fold" } },
371373
{ "n", "zc", actions.close_fold, { desc = "Collapse fold" } },
372374
{ "n", "h", actions.close_fold, { desc = "Collapse fold" } },
373375
{ "n", "za", actions.toggle_fold, { desc = "Toggle fold" } },
@@ -385,6 +387,8 @@ require("diffview").setup({
385387
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
386388
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
387389
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
390+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
391+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
388392
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
389393
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
390394
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },

doc/diffview.txt

+10
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,16 @@ select_prev_entry *diffview-actions-select_prev_en
11751175

11761176
Select the entry preceding the subject.
11771177

1178+
select_first_entry *diffview-actions-select_first_entry*
1179+
Contexts: `view`, `file_panel`, `file_history_panel`
1180+
1181+
Select the first entry.
1182+
1183+
select_last_entry *diffview-actions-select_last_entry*
1184+
Contexts: `view`, `file_panel`, `file_history_panel`
1185+
1186+
Select the last entry.
1187+
11781188
stage_all *diffview-actions-stage_all*
11791189
Contexts: `diff_view`, `file_panel`
11801190

doc/diffview_defaults.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ DEFAULT CONFIG *diffview.defaults*
9797
-- tabpage is a Diffview.
9898
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
9999
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
100+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
101+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
100102
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
101103
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
102104
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
@@ -162,6 +164,8 @@ DEFAULT CONFIG *diffview.defaults*
162164
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
163165
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
164166
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
167+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
168+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
165169
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
166170
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
167171
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
@@ -186,9 +190,7 @@ DEFAULT CONFIG *diffview.defaults*
186190
{ "n", "y", actions.copy_hash, { desc = "Copy the commit hash of the entry under the cursor" } },
187191
{ "n", "L", actions.open_commit_log, { desc = "Show commit details" } },
188192
{ "n", "X", actions.restore_entry, { desc = "Restore file to the state from the selected entry" } },
189-
{ "n", "zr", actions.open_fold, { desc = "Expand fold" } },
190193
{ "n", "zo", actions.open_fold, { desc = "Expand fold" } },
191-
{ "n", "zm", actions.close_fold, { desc = "Collapse fold" } },
192194
{ "n", "zc", actions.close_fold, { desc = "Collapse fold" } },
193195
{ "n", "h", actions.close_fold, { desc = "Collapse fold" } },
194196
{ "n", "za", actions.toggle_fold, { desc = "Toggle fold" } },
@@ -206,6 +208,8 @@ DEFAULT CONFIG *diffview.defaults*
206208
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
207209
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
208210
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
211+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
212+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
209213
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
210214
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
211215
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },

lua/diffview/actions.lua

+2
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ local action_names = {
635635
"select_entry",
636636
"select_next_entry",
637637
"select_prev_entry",
638+
"select_first_entry",
639+
"select_last_entry",
638640
"stage_all",
639641
"toggle_files",
640642
"toggle_flatten_dirs",

lua/diffview/config.lua

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ M.defaults = {
124124
-- tabpage is a Diffview.
125125
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
126126
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
127+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
128+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
127129
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
128130
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
129131
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
@@ -190,6 +192,8 @@ M.defaults = {
190192
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
191193
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
192194
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
195+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
196+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
193197
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
194198
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
195199
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
@@ -232,6 +236,8 @@ M.defaults = {
232236
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
233237
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
234238
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
239+
{ "n", "[F", actions.select_first_entry, { desc = "Open the diff for the first file" } },
240+
{ "n", "]F", actions.select_last_entry, { desc = "Open the diff for the last file" } },
235241
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
236242
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
237243
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },

lua/diffview/scene/views/diff/listeners.lua

+12
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ return function(view)
6565
view:close()
6666
end
6767
end,
68+
select_first_entry = function()
69+
local files = view.panel:ordered_file_list()
70+
if files and #files > 0 then
71+
view:set_file(files[1], false, true)
72+
end
73+
end,
74+
select_last_entry = function()
75+
local files = view.panel:ordered_file_list()
76+
if files and #files > 0 then
77+
view:set_file(files[#files], false, true)
78+
end
79+
end,
6880
select_next_entry = function()
6981
view:next_file(true)
7082
end,

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

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ return function(view)
5959
select_prev_entry = function()
6060
view:prev_item()
6161
end,
62+
select_first_entry = function()
63+
local entry = view.panel.entries[1]
64+
if entry and #entry.files > 0 then
65+
view:set_file(entry.files[1])
66+
end
67+
end,
68+
select_last_entry = function()
69+
local entry = view.panel.entries[#view.panel.entries]
70+
if entry and #entry.files > 0 then
71+
view:set_file(entry.files[#entry.files])
72+
end
73+
end,
6274
next_entry = function()
6375
view.panel:highlight_next_file()
6476
end,

0 commit comments

Comments
 (0)