Skip to content

Commit

Permalink
fix(source_selector): fix bug with tabs_layout, fixes #848 (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhat-vo committed Apr 17, 2023
1 parent 92624d0 commit 7a6b0d4
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions lua/neo-tree/ui/selector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,58 @@ M.get_selector = function(state, width)
.. text_with_hl("", hl_background)
end
else -- config.source_selector.tab_labels == "start", "end", "center"
local tmp = ""
for _, tab in ipairs(tabs) do
tmp = tmp
-- calculate padding based on tabs_layout
local pad_length = width - length_sum
local left_pad, right_pad = 0, 0
if pad_length > 0 then
if tabs_layout == "start" then
left_pad, right_pad = 0, pad_length
elseif tabs_layout == "end" then
left_pad, right_pad = pad_length, 0
elseif tabs_layout == "center" then
left_pad, right_pad = pad_length / 2, math.ceil(pad_length / 2)
end
end

for i, tab in ipairs(tabs) do
if width == 0 then
break
end

-- only render trunc_char if there is no space for the tab
local sep_length = tab.length - tab.text_length
if width <= sep_length + 1 then
return_string = return_string
.. text_with_hl(trunc_char .. add_padding(width - 1), hl_background)
width = 0
break
end

-- tab_length should not exceed width
local tab_length = width < tab.length and width or tab.length
width = width - tab_length

-- add padding for first and last tab
local tab_text = tab.text
if i == 1 then
tab_text = add_padding(left_pad) .. tab_text
tab_length = tab_length + left_pad
end
if i == #tabs then
tab_text = tab_text .. add_padding(right_pad)
tab_length = tab_length + right_pad
end

return_string = return_string
.. render_tab(
tab.left,
tab.right,
tab.sep_hl,
tab.text,
text_layout(tab_text, tabs_layout, tab_length - sep_length, trunc_char),
tab.tab_hl,
calc_click_id_from_source(winid, tab.index)
)
end
return_string = return_string .. text_layout(tmp, tabs_layout, width, trunc_char)
end
return return_string .. "%<%0@v:lua.___neotree_selector_click@"
end
Expand Down

0 comments on commit 7a6b0d4

Please sign in to comment.