Skip to content

fix: remove use of goto #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 23 additions & 22 deletions lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,31 +426,32 @@ 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
repeat
if component.enabled == false then
break
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

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
end
component_wanted_width = component_wanted_width or actual_width
wanted_width = wanted_width + component_wanted_width
::continue::
component_wanted_width = component_wanted_width or actual_width
wanted_width = wanted_width + component_wanted_width
until true
end

line.wanted_width = wanted_width
Expand Down
Loading