Skip to content

Commit e41367c

Browse files
committed
feat(config): add auto_close_on_empty option
Automatically close diffview when the last working/conflicting file has been staged. Useful for quick staging workflows.
1 parent 61ace22 commit e41367c

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

doc/diffview_defaults.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ DEFAULT CONFIG *diffview.defaults*
1111
show_help_hints = true, -- Show hints for how to open the help panel
1212
watch_index = true, -- Update views and index buffers when the git index changes.
1313
hide_merge_artifacts = false, -- Hide merge artifact files (*.orig, *.BACKUP.*, *.BASE.*, *.LOCAL.*, *.REMOTE.*)
14+
auto_close_on_empty = false, -- Close diffview when the last file is staged/resolved
1415
icons = { -- Only applies when use_icons is true.
1516
folder_closed = "",
1617
folder_open = "",

lua/diffview/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ M.defaults = {
4545
show_help_hints = true,
4646
watch_index = true,
4747
hide_merge_artifacts = false, -- Hide merge artifact files (*.orig, *.BACKUP.*, etc.)
48+
auto_close_on_empty = false, -- Automatically close diffview when the last file is staged/resolved
4849
icons = {
4950
folder_closed = "",
5051
folder_open = "",

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ local lazy = require("diffview.lazy")
44
local EventName = lazy.access("diffview.events", "EventName") ---@type EventName|LazyModule
55
local RevType = lazy.access("diffview.vcs.rev", "RevType") ---@type RevType|LazyModule
66
local actions = lazy.require("diffview.actions") ---@module "diffview.actions"
7+
local config = lazy.require("diffview.config") ---@module "diffview.config"
8+
local lib = lazy.require("diffview.lib") ---@module "diffview.lib"
79
local utils = lazy.require("diffview.utils") ---@module "diffview.utils"
810
local vcs_utils = lazy.require("diffview.vcs.utils") ---@module "diffview.vcs.utils"
911

@@ -200,6 +202,13 @@ return function(view)
200202
view:update_files(
201203
vim.schedule_wrap(function()
202204
view.panel:highlight_cur_file()
205+
-- Auto-close if all working/conflicting files have been staged.
206+
if config.get_config().auto_close_on_empty then
207+
if #view.files.working == 0 and #view.files.conflicting == 0 then
208+
view:close()
209+
lib.dispose_view(view)
210+
end
211+
end
203212
end)
204213
)
205214
view.emitter:emit(EventName.FILES_STAGED, view)
@@ -220,6 +229,13 @@ return function(view)
220229

221230
view:update_files(function()
222231
view.panel:highlight_cur_file()
232+
-- Auto-close if all working/conflicting files have been staged.
233+
if config.get_config().auto_close_on_empty then
234+
if #view.files.working == 0 and #view.files.conflicting == 0 then
235+
view:close()
236+
lib.dispose_view(view)
237+
end
238+
end
223239
end)
224240
view.emitter:emit(EventName.FILES_STAGED, view)
225241
end

0 commit comments

Comments
 (0)