mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
fix(statuscolumn): don't update clicks if current width is 0 (#24459)
This commit is contained in:
@ -686,7 +686,7 @@ static void get_statuscol_str(win_T *wp, linenr_T lnum, int virtnum, statuscol_T
|
|||||||
int width = build_statuscol_str(wp, lnum, relnum, stcp);
|
int width = build_statuscol_str(wp, lnum, relnum, stcp);
|
||||||
// Force a redraw in case of error or when truncated
|
// Force a redraw in case of error or when truncated
|
||||||
if (*wp->w_p_stc == NUL || (stcp->truncate > 0 && wp->w_nrwidth < MAX_NUMBERWIDTH)) {
|
if (*wp->w_p_stc == NUL || (stcp->truncate > 0 && wp->w_nrwidth < MAX_NUMBERWIDTH)) {
|
||||||
if (stcp->truncate) { // Avoid truncating 'statuscolumn'
|
if (stcp->truncate > 0) { // Avoid truncating 'statuscolumn'
|
||||||
wp->w_nrwidth = MIN(MAX_NUMBERWIDTH, wp->w_nrwidth + stcp->truncate);
|
wp->w_nrwidth = MIN(MAX_NUMBERWIDTH, wp->w_nrwidth + stcp->truncate);
|
||||||
wp->w_nrwidth_width = wp->w_nrwidth;
|
wp->w_nrwidth_width = wp->w_nrwidth;
|
||||||
} else { // 'statuscolumn' reset due to error
|
} else { // 'statuscolumn' reset due to error
|
||||||
|
@ -890,7 +890,9 @@ void draw_tabline(void)
|
|||||||
/// @return The width of the built status column string for line "lnum"
|
/// @return The width of the built status column string for line "lnum"
|
||||||
int build_statuscol_str(win_T *wp, linenr_T lnum, long relnum, statuscol_T *stcp)
|
int build_statuscol_str(win_T *wp, linenr_T lnum, long relnum, statuscol_T *stcp)
|
||||||
{
|
{
|
||||||
bool fillclick = relnum >= 0 && lnum == wp->w_topline;
|
// Only update click definitions once per window per redraw.
|
||||||
|
// Don't update when current width is 0, since it will be redrawn again if not empty.
|
||||||
|
const bool fillclick = relnum >= 0 && stcp->width > 0 && lnum == wp->w_topline;
|
||||||
|
|
||||||
if (relnum >= 0) {
|
if (relnum >= 0) {
|
||||||
set_vim_var_nr(VV_LNUM, lnum);
|
set_vim_var_nr(VV_LNUM, lnum);
|
||||||
@ -903,7 +905,6 @@ int build_statuscol_str(win_T *wp, linenr_T lnum, long relnum, statuscol_T *stcp
|
|||||||
stcp->width, &stcp->hlrec, fillclick ? &clickrec : NULL, stcp);
|
stcp->width, &stcp->hlrec, fillclick ? &clickrec : NULL, stcp);
|
||||||
xfree(stc);
|
xfree(stc);
|
||||||
|
|
||||||
// Only update click definitions once per window per redraw
|
|
||||||
if (fillclick) {
|
if (fillclick) {
|
||||||
stl_clear_click_defs(wp->w_statuscol_click_defs, wp->w_statuscol_click_defs_size);
|
stl_clear_click_defs(wp->w_statuscol_click_defs, wp->w_statuscol_click_defs_size);
|
||||||
wp->w_statuscol_click_defs = stl_alloc_click_defs(wp->w_statuscol_click_defs, stcp->width,
|
wp->w_statuscol_click_defs = stl_alloc_click_defs(wp->w_statuscol_click_defs, stcp->width,
|
||||||
@ -1973,8 +1974,8 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
|
|||||||
|
|
||||||
int width = vim_strsize(out);
|
int width = vim_strsize(out);
|
||||||
// Return truncated width for 'statuscolumn'
|
// Return truncated width for 'statuscolumn'
|
||||||
if (stcp != NULL && width > maxwidth) {
|
if (stcp != NULL && width > stcp->width) {
|
||||||
stcp->truncate = width - maxwidth;
|
stcp->truncate = width - stcp->width;
|
||||||
}
|
}
|
||||||
if (maxwidth > 0 && width > maxwidth) {
|
if (maxwidth > 0 && width > maxwidth) {
|
||||||
// Result is too long, must truncate somewhere.
|
// Result is too long, must truncate somewhere.
|
||||||
|
@ -9,6 +9,7 @@ local exec_lua = helpers.exec_lua
|
|||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
local pcall_err = helpers.pcall_err
|
local pcall_err = helpers.pcall_err
|
||||||
|
local assert_alive = helpers.assert_alive
|
||||||
|
|
||||||
local mousemodels = { "extend", "popup", "popup_setpos" }
|
local mousemodels = { "extend", "popup", "popup_setpos" }
|
||||||
|
|
||||||
@ -577,8 +578,8 @@ describe('statuscolumn', function()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
it('click labels do not leak memory', function()
|
it('click labels do not leak memory #21878', function()
|
||||||
command([[
|
exec([[
|
||||||
set laststatus=2
|
set laststatus=2
|
||||||
setlocal statuscolumn=%0@MyClickFunc@abcd%T
|
setlocal statuscolumn=%0@MyClickFunc@abcd%T
|
||||||
4vsplit
|
4vsplit
|
||||||
@ -590,6 +591,18 @@ describe('statuscolumn', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('click labels do not crash when initial width is 0 #24428', function()
|
||||||
|
exec([[
|
||||||
|
set nonumber
|
||||||
|
bwipe!
|
||||||
|
setlocal statuscolumn=abcd
|
||||||
|
redraw
|
||||||
|
setlocal statuscolumn=%0@MyClickFunc@abcd%T
|
||||||
|
redraw
|
||||||
|
]])
|
||||||
|
assert_alive()
|
||||||
|
end)
|
||||||
|
|
||||||
it('works with foldcolumn', function()
|
it('works with foldcolumn', function()
|
||||||
-- Fits maximum multibyte foldcolumn #21759
|
-- Fits maximum multibyte foldcolumn #21759
|
||||||
command([[set stc=%C%=%l\ fdc=9 fillchars=foldsep:𒀀]])
|
command([[set stc=%C%=%l\ fdc=9 fillchars=foldsep:𒀀]])
|
||||||
|
Reference in New Issue
Block a user