aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/drawline.c
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2024-01-01 14:24:48 +0100
committerLewis Russell <me@lewisr.dev>2024-01-04 11:52:37 +0000
commitfa61e0c047954e7eb494ee02144a4dc71a42b3b2 (patch)
tree7fe807a23591eec0ea2286cc3e0845c7f620538e /src/nvim/drawline.c
parent444f37fe510f4c28c59bade40d7ba152a5ee8f7c (diff)
downloadrneovim-fa61e0c047954e7eb494ee02144a4dc71a42b3b2.tar.gz
rneovim-fa61e0c047954e7eb494ee02144a4dc71a42b3b2.tar.bz2
rneovim-fa61e0c047954e7eb494ee02144a4dc71a42b3b2.zip
refactor(column): define and use maximum 'statuscolumn' width
Problem: The maximum 'statuscolumn' width and grow behavior is undocumented. Solution: Define, use and document the maximum 'statuscolumn' width and grow behavior.
Diffstat (limited to 'src/nvim/drawline.c')
-rw-r--r--src/nvim/drawline.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index dbcd4ace8c..22eb0b9c31 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -563,9 +563,6 @@ static void draw_lnum_col(win_T *wp, winlinevars_T *wlv, int sign_num_attr, int
}
/// Build and draw the 'statuscolumn' string for line "lnum" in window "wp".
-/// Fill "stcp" with the built status column string and attributes.
-///
-/// @param[out] stcp Status column attributes
static void draw_statuscol(win_T *wp, winlinevars_T *wlv, linenr_T lnum, int virtnum,
statuscol_T *stcp)
{
@@ -579,11 +576,9 @@ static void draw_statuscol(win_T *wp, winlinevars_T *wlv, linenr_T lnum, int vir
if (wp->w_statuscol_line_count != wp->w_nrwidth_line_count) {
wp->w_statuscol_line_count = wp->w_nrwidth_line_count;
set_vim_var_nr(VV_VIRTNUM, 0);
- build_statuscol_str(wp, wp->w_nrwidth_line_count, 0, buf, stcp);
- if (stcp->truncate > 0) {
- // Add truncated width to avoid unnecessary redraws
- int addwidth = MIN(stcp->truncate, MAX_NUMBERWIDTH - wp->w_nrwidth);
- stcp->truncate = 0;
+ int width = build_statuscol_str(wp, wp->w_nrwidth_line_count, 0, buf, stcp);
+ if (width > stcp->width) {
+ int addwidth = MIN(width - stcp->width, MAX_STCWIDTH - stcp->width);
stcp->width += addwidth;
wp->w_nrwidth += addwidth;
wp->w_nrwidth_width = wp->w_nrwidth;
@@ -594,13 +589,13 @@ static void draw_statuscol(win_T *wp, winlinevars_T *wlv, linenr_T lnum, int vir
int width = build_statuscol_str(wp, lnum, relnum, buf, stcp);
// 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 || (width > stcp->width && stcp->width < MAX_STCWIDTH)) {
if (*wp->w_p_stc == NUL) { // 'statuscolumn' reset due to error
wp->w_nrwidth_line_count = 0;
wp->w_nrwidth = (wp->w_p_nu || wp->w_p_rnu) * number_width(wp);
} else { // Avoid truncating 'statuscolumn'
+ wp->w_nrwidth += MIN(width - stcp->width, MAX_STCWIDTH - stcp->width);
wp->w_nrwidth_width = wp->w_nrwidth;
- wp->w_nrwidth = MIN(MAX_NUMBERWIDTH, wp->w_nrwidth + stcp->truncate);
}
wp->w_redr_statuscol = true;
return;