fix: wrong highlights on inactive mode with last commit

This commit is contained in:
shadmansaleh 2021-09-19 12:20:07 +06:00
parent 7147989f5f
commit 260133ce63
4 changed files with 13 additions and 16 deletions

View File

@ -139,7 +139,7 @@ local function statusline(sections, is_focused)
if #section_data > 0 then
if not applied_midsection_devider and section_name > 'c' then
applied_midsection_devider = true
section_data = '%#' .. modules.highlight.append_mode 'lualine_c' .. '#%=' .. section_data
section_data = modules.highlight.format_highlight 'lualine_c' .. '%=' .. section_data
end
if not applied_trunc and section_name > 'b' then
applied_trunc = true

View File

@ -57,8 +57,7 @@ function FileType:apply_icon()
if icon and self.options.colored then
local highlight_color = modules.utils.extract_highlight_colors(icon_highlight_group, 'fg')
local is_focused = modules.utils.is_focused()
local default_highlight = modules.highlight.format_highlight(is_focused, self.options.self.section)
local default_highlight = modules.highlight.format_highlight(self.options.self.section)
local icon_highlight = self.options.self.section .. '_' .. icon_highlight_group
if not modules.highlight.highlight_exists(icon_highlight .. '_normal') then
icon_highlight = modules.highlight.create_component_highlight_group(

View File

@ -90,7 +90,13 @@ end
-- @description: adds '_mode' at end of highlight_group
-- @param highlight_group:(string) name of highlight group
-- @return: (string) highlight group name with mode
function M.append_mode(highlight_group)
function M.append_mode(highlight_group, is_focused)
if is_focused == nil then
is_focused = modules.utils.is_focused()
end
if is_focused == false then
return highlight_group .. '_inactive'
end
local mode = require('lualine.utils.mode').get_mode()
if
mode == 'VISUAL'
@ -217,11 +223,7 @@ function M.component_format_highlight(highlight_name)
if highlight_name:find 'no_mode' == #highlight_name - #'no_mode' + 1 then
return '%#' .. highlight_group .. '#'
end
if modules.utils.is_focused() then
highlight_group = M.append_mode(highlight_group)
else
highlight_group = highlight_group .. '_inactive'
end
highlight_group = M.append_mode(highlight_group)
if M.highlight_exists(highlight_group) then
return '%#' .. highlight_group .. '#'
else
@ -229,16 +231,12 @@ function M.component_format_highlight(highlight_name)
end
end
function M.format_highlight(is_focused, highlight_group)
function M.format_highlight(highlight_group, is_focused)
if highlight_group > 'lualine_c' and not M.highlight_exists(highlight_group .. '_normal') then
highlight_group = 'lualine_' .. section_highlight_map[highlight_group:match 'lualine_(.)']
end
local highlight_name
if not is_focused then
highlight_name = highlight_group .. [[_inactive]]
else
highlight_name = M.append_mode(highlight_group)
end
highlight_name = M.append_mode(highlight_group, is_focused)
if M.highlight_exists(highlight_name) then
return '%#' .. highlight_name .. '#'
end

View File

@ -6,7 +6,7 @@ local utils = require 'lualine.utils.utils'
local highlight = require 'lualine.highlight'
-- Returns formated string for a section
function M.draw_section(section, section_name, is_focused)
local highlight_name = highlight.format_highlight(is_focused, 'lualine_' .. section_name)
local highlight_name = highlight.format_highlight('lualine_' .. section_name, is_focused)
local status = {}
for _, component in pairs(section) do