Skip to content

Commit

Permalink
Add component append
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey committed Nov 28, 2023
1 parent ec64f37 commit c1ff05e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lua/neogit/lib/ui/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ function Component:get_highlight()
return self.options.highlight or (self.parent and self.parent:get_highlight() or nil)
end

function Component:append(c)
table.insert(self.children, c)
return self
end

function Component.new(f)
local x = {}
setmetatable(x, {
Expand Down
10 changes: 9 additions & 1 deletion lua/neogit/lib/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ function Ui:get_component_stack_under_cursor()
end)
end

function Ui:get_fold_under_cursor()
local cursor = vim.api.nvim_win_get_cursor(0)
return self:find_component(function(c)
return c.options.foldable and c:is_under_cursor(cursor)
end)
end

function Ui:get_component_stack_in_linewise_selection()
local range = { vim.fn.getpos("v")[2], vim.fn.getpos(".")[2] }
table.sort(range)
Expand Down Expand Up @@ -313,7 +320,8 @@ function Ui:_render(first_line, first_col, parent, components, flags)
if c.options.foldable then
self.buf:buffered_create_fold(
#self.buf.line_buffer - (c.position.row_end - c.position.row_start),
#self.buf.line_buffer
#self.buf.line_buffer,
not c.options.folded
)
end
end
Expand Down

0 comments on commit c1ff05e

Please sign in to comment.