From 260133ce631da2047a00b55f25ffc553c2ab4318 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sun, 19 Sep 2021 12:20:07 +0600 Subject: [PATCH] fix: wrong highlights on inactive mode with last commit --- lua/lualine.lua | 2 +- lua/lualine/components/filetype.lua | 3 +-- lua/lualine/highlight.lua | 22 ++++++++++------------ lua/lualine/utils/section.lua | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lua/lualine.lua b/lua/lualine.lua index 84af95d..732f7e1 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -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 diff --git a/lua/lualine/components/filetype.lua b/lua/lualine/components/filetype.lua index 795f7e3..fac7c57 100644 --- a/lua/lualine/components/filetype.lua +++ b/lua/lualine/components/filetype.lua @@ -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( diff --git a/lua/lualine/highlight.lua b/lua/lualine/highlight.lua index a64d8c4..b441bd7 100644 --- a/lua/lualine/highlight.lua +++ b/lua/lualine/highlight.lua @@ -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 diff --git a/lua/lualine/utils/section.lua b/lua/lualine/utils/section.lua index a83c5ed..cb5f11b 100644 --- a/lua/lualine/utils/section.lua +++ b/lua/lualine/utils/section.lua @@ -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