Skip to content

Commit 3e27322

Browse files
cosmicbuffalodlyongemallo
authored andcommitted
feat: add :DiffviewToggle command (sindrets#517)
1 parent 1b386ce commit 3e27322

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lua/diffview/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function M.open(args)
133133
end
134134
end
135135

136+
136137
---@param range? { [1]: integer, [2]: integer }
137138
---@param args string[]
138139
function M.file_history(range, args)
@@ -157,6 +158,16 @@ function M.close(tabpage)
157158
end
158159
end
159160

161+
-- @param args string[]
162+
function M.toggle(args)
163+
local view = lib.get_current_view()
164+
if view then
165+
M.close()
166+
else
167+
M.open(args)
168+
end
169+
end
170+
160171
function M.completion(_, cmd_line, cur_pos)
161172
local ctx = arg_parser.scan(cmd_line, { cur_pos = cur_pos, allow_ex_range = true })
162173
local cmd = ctx.args[1]

plugin/diffview.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ command("DiffviewOpen", function(ctx)
2424
diffview.open(arg_parser.scan(ctx.args).args)
2525
end, { nargs = "*", complete = completion })
2626

27+
command("DiffviewToggle", function(ctx)
28+
diffview.toggle(arg_parser.scan(ctx.args).args)
29+
end, { nargs = "*", complete = completion })
30+
2731
command("DiffviewFileHistory", function(ctx)
2832
local range
2933

0 commit comments

Comments
 (0)