Skip to content

Commit

Permalink
feat: hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas committed Jul 28, 2024
1 parent 938b1f2 commit 6c8ff4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ hunk.setup({
folder_open = "",
folder_closed = "",
},

-- Called right after each window and buffer are created.
hooks = {
---@param _context { buf: number, tree: NuiTree, opts: table }
on_tree_mount = function(_context) end,
---@param _context { buf: number, win: number }
on_diff_mount = function(_context) end,
},
})
```

Expand Down
6 changes: 4 additions & 2 deletions lua/hunk/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ local M = {
},

hooks = {
on_tree_mount = function() end,
on_diff_mount = function() end,
---@param _context { buf: number, tree: NuiTree, opts: table }
on_tree_mount = function(_context) end,
---@param _context { buf: number, win: number }
on_diff_mount = function(_context) end,
},
}

Expand Down
2 changes: 2 additions & 0 deletions lua/hunk/ui/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function M.create(window, params)
end, { buffer = buf })
end

config.hooks.on_diff_mount({ buf = buf, win = window })

local function apply_signs()
api.signs.clear_signs(buf)

Expand Down
2 changes: 2 additions & 0 deletions lua/hunk/ui/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ function M.create(opts)
end, { buffer = buf })
end

config.hooks.on_tree_mount({ buf = buf, tree = tree, opts = opts })

local file_tree
if config.ui.tree.mode == "nested" then
file_tree = build_file_tree(opts.changeset)
Expand Down

0 comments on commit 6c8ff4f

Please sign in to comment.