Skip to content

Commit

Permalink
remove gotos
Browse files Browse the repository at this point in the history
  • Loading branch information
pynappo committed Jan 27, 2025
1 parent 521bb42 commit db64883
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
31 changes: 16 additions & 15 deletions lua/neo-tree/sources/common/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,23 @@ local render_content = function(config, node, state, context)
local rendered_width = 0

for _, item in ipairs(items) do
if item.enabled == false then
goto continue
end
local required_width = item.required_width or 0
if required_width > window_width then
goto continue
end
local rendered_item = renderer.render_component(item, node, state, context.available_width)
if rendered_item then
local align = item.align or "left"
should_pad[align] = add_padding(rendered_item, should_pad[align])
repeat -- doing this instead of goto continue for lua 5.1 compat
if item.enabled == false then
break
end
local required_width = item.required_width or 0
if required_width > window_width then
break
end
local rendered_item = renderer.render_component(item, node, state, context.available_width)
if rendered_item then
local align = item.align or "left"
should_pad[align] = add_padding(rendered_item, should_pad[align])

vim.list_extend(zindex_rendered[align], rendered_item)
rendered_width = rendered_width + calc_rendered_width(rendered_item)
end
::continue::
vim.list_extend(zindex_rendered[align], rendered_item)
rendered_width = rendered_width + calc_rendered_width(rendered_item)
end
until true
end

max_width = math.max(max_width, rendered_width)
Expand Down
40 changes: 19 additions & 21 deletions lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,31 +426,29 @@ local prepare_node = function(item, state)
local should_pad = false

for _, component in ipairs(renderer) do
if component.enabled == false then
goto continue
end
local component_data, component_wanted_width =
M.render_component(component, item, state, remaining_cols - (should_pad and 1 or 0))
local actual_width = 0
if component_data then
for _, data in ipairs(component_data) do
if data.text then
local padding = ""
if should_pad and #data.text and data.text:sub(1, 1) ~= " " and not data.no_padding then
padding = " "
end
data.text = padding .. data.text
should_pad = data.text:sub(#data.text) ~= " " and not data.no_next_padding
if component.enabled then
local component_data, component_wanted_width =
M.render_component(component, item, state, remaining_cols - (should_pad and 1 or 0))
local actual_width = 0
if component_data then
for _, data in ipairs(component_data) do
if data.text then
local padding = ""
if should_pad and #data.text and data.text:sub(1, 1) ~= " " and not data.no_padding then
padding = " "
end
data.text = padding .. data.text
should_pad = data.text:sub(#data.text) ~= " " and not data.no_next_padding

actual_width = actual_width + vim.api.nvim_strwidth(data.text)
line:append(data.text, data.highlight)
remaining_cols = remaining_cols - vim.fn.strchars(data.text)
actual_width = actual_width + vim.api.nvim_strwidth(data.text)
line:append(data.text, data.highlight)
remaining_cols = remaining_cols - vim.fn.strchars(data.text)
end
end
end
component_wanted_width = component_wanted_width or actual_width
wanted_width = wanted_width + component_wanted_width
end
component_wanted_width = component_wanted_width or actual_width
wanted_width = wanted_width + component_wanted_width
::continue::
end

line.wanted_width = wanted_width
Expand Down

0 comments on commit db64883

Please sign in to comment.