Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(statuscolumn): use extmarks cursorline hl #574

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading