-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
feat: support for statuscolumn #1037
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -26,6 +26,52 @@ local signs_staged --- @type Gitsigns.Signs | |||||||
|
||||||||
local M = {} | ||||||||
|
||||||||
local statuscolumn_active = false | ||||||||
|
||||||||
--- @param bufnr? integer | ||||||||
--- @param top? integer | ||||||||
--- @param bot? integer | ||||||||
local function redraw_statuscol(bufnr, top, bot) | ||||||||
if statuscolumn_active then | ||||||||
api.nvim__redraw({ | ||||||||
buf = bufnr, | ||||||||
range = { top, bot }, | ||||||||
statuscolumn = true, | ||||||||
}) | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
function M.statuscolumn() | ||||||||
if not statuscolumn_active then | ||||||||
config.signcolumn = false | ||||||||
statuscolumn_active = true | ||||||||
end | ||||||||
|
||||||||
local res = {} | ||||||||
local res_len = 0 | ||||||||
local max_pad = 0 | ||||||||
local lnum = vim.v.lnum | ||||||||
for _, signs in pairs({ signs_normal, signs_staged }) do | ||||||||
if next(signs.signs) then | ||||||||
max_pad = 2 | ||||||||
end | ||||||||
local marks = api.nvim_buf_get_extmarks(0, signs.ns, { lnum - 1, 0 }, { lnum - 1, -1 }, {}) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I suppose there is no need to change the function signature like I suggested on matrix. |
||||||||
for _, mark in pairs(marks) do | ||||||||
local id = mark[1] | ||||||||
local s = signs.signs[id] | ||||||||
if s then | ||||||||
table.insert(res, '%#' .. s[2] .. '#') | ||||||||
table.insert(res, s[1]) | ||||||||
res_len = res_len + vim.str_utfindex(s[1]) | ||||||||
table.insert(res, '%#NONE#') | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want |
||||||||
end | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
local pad = math.max(0, max_pad - res_len) | ||||||||
return table.concat(res) .. string.rep(' ', pad) | ||||||||
end | ||||||||
|
||||||||
--- @param bufnr integer | ||||||||
--- @param signs Gitsigns.Signs | ||||||||
--- @param hunks Gitsigns.Hunk.Hunk[] | ||||||||
|
@@ -77,6 +123,9 @@ local function apply_win_signs(bufnr, top, bot, clear) | |||||||
if signs_staged then | ||||||||
apply_win_signs0(bufnr, signs_staged, bcache.hunks_staged, top, bot, clear, false) | ||||||||
end | ||||||||
if clear then | ||||||||
redraw_statuscol(bufnr, top, bot) | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
--- @param blame table<integer,Gitsigns.BlameInfo?>? | ||||||||
|
@@ -349,7 +398,7 @@ function M.show_deleted_in_float(bufnr, nsd, hunk, staged) | |||||||
|
||||||||
-- Navigate to hunk | ||||||||
vim.cmd('normal ' .. tostring(hunk.removed.start) .. 'gg') | ||||||||
vim.cmd('normal ' .. vim.api.nvim_replace_termcodes('z<CR>', true, false, true)) | ||||||||
vim.cmd('normal ' .. api.nvim_replace_termcodes('z<CR>', true, false, true)) | ||||||||
end) | ||||||||
|
||||||||
local last_lnum = api.nvim_buf_line_count(bufnr) | ||||||||
|
@@ -531,6 +580,7 @@ function M.detach(bufnr, keep_signs) | |||||||
if signs_staged then | ||||||||
signs_staged:remove(bufnr) | ||||||||
end | ||||||||
redraw_statuscol(bufnr) | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
|
@@ -542,6 +592,7 @@ function M.reset_signs() | |||||||
if signs_staged then | ||||||||
signs_staged:reset() | ||||||||
end | ||||||||
redraw_statuscol() | ||||||||
end | ||||||||
|
||||||||
--- @param _cb 'win' | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you experience that both
range
andstatuscolumn
are necessary? The entire window should already be redrawn withstatuscolumn = true
. But yeah previously placing sign extmarks was what triggered redraws so since that doesn't happen here anymore I think these manual redraws are necessary.