Skip to content

Commit db64883

Browse files
committed
remove gotos
1 parent 521bb42 commit db64883

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

lua/neo-tree/sources/common/container.lua

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,23 @@ local render_content = function(config, node, state, context)
7171
local rendered_width = 0
7272

7373
for _, item in ipairs(items) do
74-
if item.enabled == false then
75-
goto continue
76-
end
77-
local required_width = item.required_width or 0
78-
if required_width > window_width then
79-
goto continue
80-
end
81-
local rendered_item = renderer.render_component(item, node, state, context.available_width)
82-
if rendered_item then
83-
local align = item.align or "left"
84-
should_pad[align] = add_padding(rendered_item, should_pad[align])
74+
repeat -- doing this instead of goto continue for lua 5.1 compat
75+
if item.enabled == false then
76+
break
77+
end
78+
local required_width = item.required_width or 0
79+
if required_width > window_width then
80+
break
81+
end
82+
local rendered_item = renderer.render_component(item, node, state, context.available_width)
83+
if rendered_item then
84+
local align = item.align or "left"
85+
should_pad[align] = add_padding(rendered_item, should_pad[align])
8586

86-
vim.list_extend(zindex_rendered[align], rendered_item)
87-
rendered_width = rendered_width + calc_rendered_width(rendered_item)
88-
end
89-
::continue::
87+
vim.list_extend(zindex_rendered[align], rendered_item)
88+
rendered_width = rendered_width + calc_rendered_width(rendered_item)
89+
end
90+
until true
9091
end
9192

9293
max_width = math.max(max_width, rendered_width)

lua/neo-tree/ui/renderer.lua

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -426,31 +426,29 @@ local prepare_node = function(item, state)
426426
local should_pad = false
427427

428428
for _, component in ipairs(renderer) do
429-
if component.enabled == false then
430-
goto continue
431-
end
432-
local component_data, component_wanted_width =
433-
M.render_component(component, item, state, remaining_cols - (should_pad and 1 or 0))
434-
local actual_width = 0
435-
if component_data then
436-
for _, data in ipairs(component_data) do
437-
if data.text then
438-
local padding = ""
439-
if should_pad and #data.text and data.text:sub(1, 1) ~= " " and not data.no_padding then
440-
padding = " "
441-
end
442-
data.text = padding .. data.text
443-
should_pad = data.text:sub(#data.text) ~= " " and not data.no_next_padding
429+
if component.enabled then
430+
local component_data, component_wanted_width =
431+
M.render_component(component, item, state, remaining_cols - (should_pad and 1 or 0))
432+
local actual_width = 0
433+
if component_data then
434+
for _, data in ipairs(component_data) do
435+
if data.text then
436+
local padding = ""
437+
if should_pad and #data.text and data.text:sub(1, 1) ~= " " and not data.no_padding then
438+
padding = " "
439+
end
440+
data.text = padding .. data.text
441+
should_pad = data.text:sub(#data.text) ~= " " and not data.no_next_padding
444442

445-
actual_width = actual_width + vim.api.nvim_strwidth(data.text)
446-
line:append(data.text, data.highlight)
447-
remaining_cols = remaining_cols - vim.fn.strchars(data.text)
443+
actual_width = actual_width + vim.api.nvim_strwidth(data.text)
444+
line:append(data.text, data.highlight)
445+
remaining_cols = remaining_cols - vim.fn.strchars(data.text)
446+
end
448447
end
449448
end
449+
component_wanted_width = component_wanted_width or actual_width
450+
wanted_width = wanted_width + component_wanted_width
450451
end
451-
component_wanted_width = component_wanted_width or actual_width
452-
wanted_width = wanted_width + component_wanted_width
453-
::continue::
454452
end
455453

456454
line.wanted_width = wanted_width

0 commit comments

Comments
 (0)