diff options
author | Luuk van Baal <luukvbaal@gmail.com> | 2024-06-15 05:46:43 +0200 |
---|---|---|
committer | Luuk van Baal <luukvbaal@gmail.com> | 2024-06-16 19:04:34 +0200 |
commit | ad70c9892d5b5ebcc106742386c99524f074bcea (patch) | |
tree | 13ef468ac927d78a1f35fbdf01ffc6a2e2ba914f /src/nvim/statusline.c | |
parent | 114197517f89de557333dbc6022912b2f8b4eaf5 (diff) | |
download | rneovim-ad70c9892d5b5ebcc106742386c99524f074bcea.tar.gz rneovim-ad70c9892d5b5ebcc106742386c99524f074bcea.tar.bz2 rneovim-ad70c9892d5b5ebcc106742386c99524f074bcea.zip |
feat(column)!: rework 'statuscolumn' %r/l items
Problem: A custom 'statuscolumn' needs to check a bunch of options and
placed signs to replicate the default number column.
Solution: Rework %l item to include the necessary logic to mimic the
default number column. Remove now redundant %r item.
Diffstat (limited to 'src/nvim/statusline.c')
-rw-r--r-- | src/nvim/statusline.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index b8938e5f40..ad7e4587a9 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -1017,7 +1017,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op int evaldepth = 0; int curitem = 0; - int foldsignitem = -1; bool prevchar_isflag = true; bool prevchar_isitem = false; @@ -1234,6 +1233,8 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op } int minwid = 0; int maxwid = 9999; + int foldsignitem = -1; // Start of fold or sign item + bool left_align_num = false; // Number item for should be left-aligned bool left_align = false; // Denotes that numbers should be left-padded with zeros @@ -1505,12 +1506,20 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op } case STL_LINE: - // Overload %l with v:lnum for 'statuscolumn' - if (stcp != NULL) { - if (wp->w_p_nu && !get_vim_var_nr(VV_VIRTNUM)) { - num = (int)get_vim_var_nr(VV_LNUM); + // Overload %l with v:(re)lnum for 'statuscolumn'. Place a sign when 'signcolumn' + // is set to "number". Take care of alignment for 'number' + 'relativenumber'. + if (stcp != NULL && (wp->w_p_nu || wp->w_p_rnu) && get_vim_var_nr(VV_VIRTNUM) == 0) { + if (wp->w_maxscwidth == SCL_NUM && stcp->sattrs[0].text[0]) { + goto stcsign; } - } else { + int relnum = (int)get_vim_var_nr(VV_RELNUM); + num = (!wp->w_p_rnu || (wp->w_p_nu && relnum == 0)) ? (int)get_vim_var_nr(VV_LNUM) : relnum; + left_align_num = wp->w_p_rnu && wp->w_p_nu && relnum == 0; + if (!left_align_num) { + stl_items[curitem].type = Separate; + stl_items[curitem++].start = out_p; + } + } else if (stcp == NULL) { num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) ? 0 : wp->w_cursor.lnum; } break; @@ -1609,16 +1618,9 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op case STL_ROFLAG: case STL_ROFLAG_ALT: - // Overload %r with v:relnum for 'statuscolumn' - if (stcp != NULL) { - if (wp->w_p_rnu && !get_vim_var_nr(VV_VIRTNUM)) { - num = (int)get_vim_var_nr(VV_RELNUM); - } - } else { - itemisflag = true; - if (wp->w_buffer->b_p_ro) { - str = (opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]"); - } + itemisflag = true; + if (wp->w_buffer->b_p_ro) { + str = (opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]"); } break; @@ -1632,11 +1634,12 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op case STL_FOLDCOL: // 'C' for 'statuscolumn' case STL_SIGNCOL: { // 's' for 'statuscolumn' +stcsign: if (stcp == NULL) { break; } int fdc = opt == STL_FOLDCOL ? compute_foldcolumn(wp, 0) : 0; - int width = opt == STL_FOLDCOL ? fdc > 0 : wp->w_scwidth; + int width = opt == STL_FOLDCOL ? fdc > 0 : opt == STL_SIGNCOL ? wp->w_scwidth : 1; if (width <= 0) { break; @@ -1844,7 +1847,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op // For a 'statuscolumn' sign or fold item, add an item to reset the highlight group if (foldsignitem >= 0) { - foldsignitem = -1; stl_items[curitem].type = Highlight; stl_items[curitem].start = out_p; stl_items[curitem].minwid = 0; @@ -1949,6 +1951,11 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op // Item processed, move to the next curitem++; + // For a 'statuscolumn' number item that is left aligned, add a separator item. + if (left_align_num) { + stl_items[curitem].type = Separate; + stl_items[curitem++].start = out_p; + } } *out_p = NUL; |