mirror of
https://github.com/folke/snacks.nvim
synced 2025-07-07 21:25:11 +00:00
fix(statuscolumn): right-align the current line number when relativenumber=true. Closes #1376
This commit is contained in:
parent
f5abf26777
commit
dd15e3a05a
1 changed files with 17 additions and 9 deletions
|
@ -13,12 +13,6 @@ M.meta = {
|
|||
needs_setup = true,
|
||||
}
|
||||
|
||||
-- Numbers in Neovim are weird
|
||||
-- They show when either number or relativenumber is true
|
||||
local LINE_NR = "%=%{%(&number || &relativenumber) && v:virtnum == 0 ? ("
|
||||
.. (vim.fn.has("nvim-0.11") == 1 and '"%l"' or 'v:relnum == 0 ? (&number ? "%l" : "%r") : (&relativenumber ? "%r" : "%l")')
|
||||
.. ') : ""%} '
|
||||
|
||||
---@alias snacks.statuscolumn.Component "mark"|"sign"|"fold"|"git"
|
||||
---@alias snacks.statuscolumn.Components snacks.statuscolumn.Component[]|fun(win:number,buf:number,lnum:number):snacks.statuscolumn.Component[]
|
||||
|
||||
|
@ -184,12 +178,26 @@ function M._get()
|
|||
M.setup()
|
||||
end
|
||||
local win = vim.g.statusline_winid
|
||||
local nu = vim.wo[win].number
|
||||
local rnu = vim.wo[win].relativenumber
|
||||
local show_signs = vim.v.virtnum == 0 and vim.wo[win].signcolumn ~= "no"
|
||||
local components = { "", LINE_NR, "" } -- left, middle, right
|
||||
if not show_signs and not (vim.wo[win].number or vim.wo[win].relativenumber) then
|
||||
local components = { "", "", "" } -- left, middle, right
|
||||
if not (show_signs or nu or rnu) then
|
||||
return ""
|
||||
end
|
||||
|
||||
if (nu or rnu) and vim.v.virtnum == 0 then
|
||||
local num ---@type number
|
||||
if rnu and nu and vim.v.relnum == 0 then
|
||||
num = vim.v.lnum
|
||||
elseif rnu then
|
||||
num = vim.v.relnum
|
||||
else
|
||||
num = vim.v.lnum
|
||||
end
|
||||
components[2] = "%=" .. num .. " "
|
||||
end
|
||||
|
||||
if show_signs then
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
local is_file = vim.bo[buf].buftype == ""
|
||||
|
@ -238,7 +246,7 @@ end
|
|||
function M.get()
|
||||
local win = vim.g.statusline_winid
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
local key = ("%d:%d:%d:%d"):format(win, buf, vim.v.lnum, vim.v.virtnum ~= 0 and 1 or 0)
|
||||
local key = ("%d:%d:%d:%d:%d"):format(win, buf, vim.v.lnum, vim.v.virtnum ~= 0 and 1 or 0, vim.v.relnum)
|
||||
if cache[key] then
|
||||
return cache[key]
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue