Skip to content

Commit

Permalink
fix(statuscolumn): use extmarks cursorline hl
Browse files Browse the repository at this point in the history
  • Loading branch information
minusfive committed Jan 17, 2025
1 parent 706b1ab commit 10cd9d4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lua/snacks/statuscolumn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ local config = Snacks.config.get("statuscolumn", defaults)

---@private
---@alias snacks.statuscolumn.Sign.type "mark"|"sign"|"fold"|"git"
---@alias snacks.statuscolumn.Sign {name:string, text:string, texthl:string, priority:number, type:snacks.statuscolumn.Sign.type}
---@alias snacks.statuscolumn.Sign {name:string, text:string, texthl:string, culhl: string, priority:number, type:snacks.statuscolumn.Sign.type}

-- Cache for signs per buffer and line
---@type table<number,table<number,snacks.statuscolumn.Sign[]>>
Expand Down Expand Up @@ -114,6 +114,7 @@ function M.buf_signs(buf)
type = M.is_git_sign(name) and "git" or "sign",
text = extmark[4].sign_text,
texthl = extmark[4].sign_hl_group,
culhl = extmark[4].cursorline_hl_group,
priority = extmark[4].priority,
})
end
Expand Down Expand Up @@ -164,17 +165,19 @@ end

---@private
---@param sign? snacks.statuscolumn.Sign
function M.icon(sign)
---@param is_cul? boolean -- is cursorline?
function M.icon(sign, is_cul)
if not sign then
return " "
end
local key = (sign.text or "") .. (sign.texthl or "")
local hl = is_cul and sign.culhl or sign.texthl
local key = (sign.text or "") .. (hl or "")
if icon_cache[key] then
return icon_cache[key]
end
local text = vim.fn.strcharpart(sign.text or "", 0, 2) ---@type string
text = text .. string.rep(" ", 2 - vim.fn.strchars(text))
icon_cache[key] = sign.texthl and ("%#" .. sign.texthl .. "#" .. text .. "%*") or text
icon_cache[key] = hl and ("%#" .. hl .. "#" .. text .. "%*") or text
return icon_cache[key]
end

Expand Down Expand Up @@ -220,8 +223,11 @@ function M._get()
right.texthl = git.texthl
end
end
components[1] = left and M.icon(left) or " " -- left
components[3] = is_file and (right and M.icon(right) or " ") or "" -- right

local is_cul = vim.v.relnum == 0 -- is cursorline?

components[1] = left and M.icon(left, is_cul) or " " -- left
components[3] = is_file and (right and M.icon(right, is_cul) or " ") or "" -- right
else
components[1] = " "
components[3] = is_file and " " or ""
Expand Down

0 comments on commit 10cd9d4

Please sign in to comment.