Fix various visual bugs in components transitional sep
This commit is contained in:
parent
f728edd31d
commit
c9b5f364dc
|
@ -83,7 +83,17 @@ local Component = {
|
||||||
self.status = highlight.component_format_highlight(
|
self.status = highlight.component_format_highlight(
|
||||||
self.options.color_highlight) .. self.status
|
self.options.color_highlight) .. self.status
|
||||||
end
|
end
|
||||||
|
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
|
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,
|
end,
|
||||||
|
|
||||||
-- Apply icon in front of component
|
-- Apply icon in front of component
|
||||||
|
@ -110,7 +120,7 @@ local Component = {
|
||||||
end
|
end
|
||||||
if separator and #separator > 0 then
|
if separator and #separator > 0 then
|
||||||
self.status = self.status .. separator
|
self.status = self.status .. separator
|
||||||
self.applied_separator = separator
|
self.applied_separator = self.applied_separator .. separator
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -139,12 +149,13 @@ local Component = {
|
||||||
status = '',
|
status = '',
|
||||||
-- Actual function that updates a component. Must be overwritten with component functionality
|
-- Actual function that updates a component. Must be overwritten with component functionality
|
||||||
-- luacheck: push no unused args
|
-- luacheck: push no unused args
|
||||||
update_status = function(self) end,
|
update_status = function(self, is_focused) end,
|
||||||
-- luacheck: pop
|
-- luacheck: pop
|
||||||
|
|
||||||
-- Driver code of the class
|
-- Driver code of the class
|
||||||
draw = function(self, default_highlight, is_focused)
|
draw = function(self, default_highlight, is_focused)
|
||||||
self.status = ''
|
self.status = ''
|
||||||
|
self.applied_separator = ''
|
||||||
|
|
||||||
if self.options.condition ~= nil and self.options.condition() ~= true then
|
if self.options.condition ~= nil and self.options.condition() ~= true then
|
||||||
return self.status
|
return self.status
|
||||||
|
@ -156,8 +167,8 @@ local Component = {
|
||||||
self:apply_icon()
|
self:apply_icon()
|
||||||
self:apply_case()
|
self:apply_case()
|
||||||
self:apply_padding()
|
self:apply_padding()
|
||||||
self:apply_section_separators()
|
|
||||||
self:apply_highlights(default_highlight)
|
self:apply_highlights(default_highlight)
|
||||||
|
self:apply_section_separators()
|
||||||
self:apply_separator()
|
self:apply_separator()
|
||||||
end
|
end
|
||||||
return self.status
|
return self.status
|
||||||
|
|
|
@ -19,7 +19,7 @@ local function apply_transitional_separators(status)
|
||||||
|
|
||||||
local function find_next_hl()
|
local function find_next_hl()
|
||||||
-- Gets the next valid hl group from str_checked
|
-- 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
|
while true do
|
||||||
if not hl_pos_start then return nil end
|
if not hl_pos_start then return nil end
|
||||||
-- When there are more that one hl group next to one another like
|
-- 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
|
-- %S{sep} is marker for right separator and
|
||||||
local sep = status:match('^%%S{(.-)}', str_checked)
|
local sep = status:match('^%%S{(.-)}', str_checked)
|
||||||
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
|
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)
|
fill_section_separator(sep, true)
|
||||||
copied_pos = str_checked
|
copied_pos = str_checked
|
||||||
elseif next_char == '%' then
|
elseif next_char == '%' then
|
||||||
|
@ -102,7 +107,6 @@ local function statusline(sections, is_focused)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return apply_transitional_separators(table.concat(status))
|
return apply_transitional_separators(table.concat(status))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,18 @@ function M.draw_section(section, section_name, is_focused)
|
||||||
status = utils.list_shrink(status)
|
status = utils.list_shrink(status)
|
||||||
local status_str = table.concat(status)
|
local status_str = table.concat(status)
|
||||||
|
|
||||||
if #status_str == 0 then return ''
|
if #status_str == 0 then return '' end
|
||||||
elseif status_str:find('%%#.*#') == 1 then
|
|
||||||
|
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
|
-- Don't prepend with old highlight when the component changes it imidiately
|
||||||
return left_sparator_string .. status_str
|
return left_sparator_string .. status_str
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue