Skip to content

Commit

Permalink
Merge pull request #36 from amedama41/feature/add_reload_all_dir
Browse files Browse the repository at this point in the history
feat: add action to reload all directories
  • Loading branch information
obaland authored Feb 14, 2024
2 parents 5b6da66 + f938873 commit 0ec178c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions doc/vfiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,11 @@ Switches to other drive(Windows) or mount point(Mac/Linux).
#### reload
Reload the `vfiler.vim` buffer.

#### reload_all_dir
Reload the `vfiler.vim` buffer.<br>
The difference between `reload` and `reload_all_dir`is the former reload only the items in directories that have been updated,<br>
while the latter reload also the items in all directories.

#### quit
Quit the `vfiler.vim` buffer.

Expand Down
18 changes: 15 additions & 3 deletions lua/vfiler/actions/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ local M = {}
-- Control buffer
------------------------------------------------------------------------------

local function reload(context, view, reload_all_dir)
context:save(view:get_item().path)
context:reload(reload_all_dir)
view:draw(context)
end

function M.quit(vfiler, context, view)
if context.options.quit then
utils.close_preview(vfiler, context, view)
Expand All @@ -27,15 +33,21 @@ function M.redraw(vfiler, context, view)
end

function M.reload(vfiler, context, view)
context:save(view:get_item().path)
context:reload()
view:draw(context)
reload(context, view, false)
end

function M.reload_all(vfiler, context, view)
VFiler.foreach(M.reload)
end

function M.reload_all_dir(vfiler, context, view)
reload(context, view, true)
end

function M.reload_all_dir_all(vfiler, context, view)
VFiler.foreach(M.reload_all_dir)
end

function M.switch_to_filer(vfiler, context, view)
-- only window style
if view:type() ~= 'window' then
Expand Down
5 changes: 3 additions & 2 deletions lua/vfiler/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ function Context:perform_auto_cd()
end

-- Reload the current directory path
function Context:reload()
---@param reload_all_dir boolean
function Context:reload(reload_all_dir)
local root_path = self.root.path
if vim.fn.getftime(root_path) > self.root.time then
if reload_all_dir or vim.fn.getftime(root_path) > self.root.time then
self:switch(root_path)
return
end
Expand Down

0 comments on commit 0ec178c

Please sign in to comment.