Fix various visual bugs in components transitional sep

This commit is contained in:
shadmansaleh 2021-08-26 17:26:13 +06:00 committed by Shadman
parent f728edd31d
commit c9b5f364dc
3 changed files with 33 additions and 8 deletions

View File

@ -83,7 +83,17 @@ local Component = {
self.status = highlight.component_format_highlight(
self.options.color_highlight) .. self.status
end
self.status = self.status .. default_highlight
if type(self.options.separator) ~= 'table' and self.status:find('%%#') then
-- Apply default highlight only when we aren't applying trans sep and
-- the component has changed it's hl. since we won't be applying
-- regular sep in those cases so ending with default hl isn't neccessay
self.status = self.status .. default_highlight
-- Also put it in applied sep so when sep get struped so does the hl
self.applied_separator = default_highlight
end
-- Prepend default hl when the component doesn't start with hl otherwise
-- color in previous component can cause side effect
if not self.status:find('^%%#') then self.status = default_highlight .. self.status end
end,
-- Apply icon in front of component
@ -110,7 +120,7 @@ local Component = {
end
if separator and #separator > 0 then
self.status = self.status .. separator
self.applied_separator = separator
self.applied_separator = self.applied_separator .. separator
end
end,
@ -139,12 +149,13 @@ local Component = {
status = '',
-- Actual function that updates a component. Must be overwritten with component functionality
-- luacheck: push no unused args
update_status = function(self) end,
update_status = function(self, is_focused) end,
-- luacheck: pop
-- Driver code of the class
draw = function(self, default_highlight, is_focused)
self.status = ''
self.applied_separator = ''
if self.options.condition ~= nil and self.options.condition() ~= true then
return self.status
@ -156,8 +167,8 @@ local Component = {
self:apply_icon()
self:apply_case()
self:apply_padding()
self:apply_section_separators()
self:apply_highlights(default_highlight)
self:apply_section_separators()
self:apply_separator()
end
return self.status

View File

@ -19,7 +19,7 @@ local function apply_transitional_separators(status)
local function find_next_hl()
-- Gets the next valid hl group from str_checked
local hl_pos_start, hl_pos_end = status:find('%%#.-#', str_checked + 1)
local hl_pos_start, hl_pos_end = status:find('%%#.-#', str_checked)
while true do
if not hl_pos_start then return nil end
-- When there are more that one hl group next to one another like
@ -67,6 +67,11 @@ local function apply_transitional_separators(status)
-- %S{sep} is marker for right separator and
local sep = status:match('^%%S{(.-)}', str_checked)
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
if status:find('^%%s', str_checked) then
-- When transitional right_sep and left_sep are right next to each other
-- and in this exact order skip the left sep as we can't draw both.
str_checked = status:find('}', str_checked) + 1
end
fill_section_separator(sep, true)
copied_pos = str_checked
elseif next_char == '%' then
@ -102,7 +107,6 @@ local function statusline(sections, is_focused)
end
end
end
return apply_transitional_separators(table.concat(status))
end

View File

@ -70,8 +70,18 @@ function M.draw_section(section, section_name, is_focused)
status = utils.list_shrink(status)
local status_str = table.concat(status)
if #status_str == 0 then return ''
elseif status_str:find('%%#.*#') == 1 then
if #status_str == 0 then return '' end
local needs_hl
local find_start_trans_sep_start, find_start_trans_sep_end = status_str:find('^%%s{.-}')
if find_start_trans_sep_start then
-- the section doesn't need to be prepended with default hl when sections
-- first component has trasitionals sep
needs_hl = status_str:find('^%%#', find_start_trans_sep_end + 1)
else needs_hl = status_str:find('^%%#') end
if needs_hl then
-- Don't prepend with old highlight when the component changes it imidiately
return left_sparator_string .. status_str
else