Skip to content

Commit 4abd70d

Browse files
committed
remove gotos
1 parent 521bb42 commit 4abd70d

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
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: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -426,31 +426,32 @@ 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+
repeat
430+
if component.enabled == false then
431+
break
432+
end
433+
local component_data, component_wanted_width =
434+
M.render_component(component, item, state, remaining_cols - (should_pad and 1 or 0))
435+
local actual_width = 0
436+
if component_data then
437+
for _, data in ipairs(component_data) do
438+
if data.text then
439+
local padding = ""
440+
if should_pad and #data.text and data.text:sub(1, 1) ~= " " and not data.no_padding then
441+
padding = " "
442+
end
443+
data.text = padding .. data.text
444+
should_pad = data.text:sub(#data.text) ~= " " and not data.no_next_padding
444445

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)
446+
actual_width = actual_width + vim.api.nvim_strwidth(data.text)
447+
line:append(data.text, data.highlight)
448+
remaining_cols = remaining_cols - vim.fn.strchars(data.text)
449+
end
448450
end
449451
end
450-
end
451-
component_wanted_width = component_wanted_width or actual_width
452-
wanted_width = wanted_width + component_wanted_width
453-
::continue::
452+
component_wanted_width = component_wanted_width or actual_width
453+
wanted_width = wanted_width + component_wanted_width
454+
until true
454455
end
455456

456457
line.wanted_width = wanted_width

0 commit comments

Comments
 (0)