From ac72d1f43770b0327a49f7869deec8c5c6529478 Mon Sep 17 00:00:00 2001 From: glepnir Date: Tue, 30 Apr 2024 15:00:18 +0800 Subject: [PATCH] no need for all elements --- lua/indentmini/init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/indentmini/init.lua b/lua/indentmini/init.lua index 8d83186..e448875 100644 --- a/lua/indentmini/init.lua +++ b/lua/indentmini/init.lua @@ -92,20 +92,24 @@ local function indentline(opt) group = g, buffer = bufnr, callback = function() + local cur_hi = 'IndentLineCurrent' local line, _ = unpack(api.nvim_win_get_cursor(0)) local level = math.floor(indent_fn(line) / vim.fn.shiftwidth()) local hls = api.nvim_get_hl(ns, {}) if level < 1 then - for k, _ in pairs(hls) do - api.nvim_set_hl(ns, k, { link = 'IndentLine' }) + for k, v in pairs(hls) do + if v.link and v.link == cur_hi then + api.nvim_set_hl(ns, k, { link = 'IndentLine' }) + break + end end return end local name = ('IndentLine%d'):format(level) - if hls[name] and hls[name].link and hls[name].link == 'IndentLineCurrent' then + if hls[name] and hls[name].link and hls[name].link == cur_hi then return end - api.nvim_set_hl(ns, name, { link = 'IndentLineCurrent' }) + api.nvim_set_hl(ns, name, { link = cur_hi }) for k, _ in pairs(hls) do if k ~= name then api.nvim_set_hl(ns, k, { link = 'IndentLine' })