diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:23:01 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:23:01 +0000 |
commit | 142d9041391780ac15b89886a54015fdc5c73995 (patch) | |
tree | 0f6b5cac1a60810a03f52826c9e67c9e2780b033 /src/nvim/plines.c | |
parent | ad86b5db74922285699ab2a1dbb2ff20e6268a33 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-142d9041391780ac15b89886a54015fdc5c73995.tar.gz rneovim-142d9041391780ac15b89886a54015fdc5c73995.tar.bz2 rneovim-142d9041391780ac15b89886a54015fdc5c73995.zip |
Merge remote-tracking branch 'upstream/master' into userreg
Diffstat (limited to 'src/nvim/plines.c')
-rw-r--r-- | src/nvim/plines.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/nvim/plines.c b/src/nvim/plines.c index cbde0cfff9..5469d94800 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -10,25 +10,20 @@ #include <string.h> #include "nvim/ascii.h" -#include "nvim/buffer.h" #include "nvim/charset.h" -#include "nvim/cursor.h" #include "nvim/decoration.h" #include "nvim/diff.h" #include "nvim/fold.h" -#include "nvim/func_attr.h" +#include "nvim/globals.h" #include "nvim/indent.h" -#include "nvim/main.h" +#include "nvim/macros.h" #include "nvim/mbyte.h" #include "nvim/memline.h" -#include "nvim/memory.h" #include "nvim/move.h" #include "nvim/option.h" #include "nvim/plines.h" -#include "nvim/screen.h" -#include "nvim/strings.h" +#include "nvim/pos.h" #include "nvim/vim.h" -#include "nvim/window.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "plines.c.generated.h" @@ -37,6 +32,9 @@ /// Functions calculating vertical size of text when displayed inside a window. /// Calls horizontal size functions defined below. +/// Return the number of window lines occupied by buffer line "lnum". +/// Includes any filler lines. +/// /// @param winheight when true limit to window height int plines_win(win_T *wp, linenr_T lnum, bool winheight) { @@ -53,7 +51,7 @@ int plines_win(win_T *wp, linenr_T lnum, bool winheight) /// @return Number of filler lines above lnum int win_get_fill(win_T *wp, linenr_T lnum) { - int virt_lines = decor_virt_lines(wp, lnum, NULL); + int virt_lines = decor_virt_lines(wp, lnum, NULL, kNone); // be quick when there are no filler lines if (diffopt_filler()) { @@ -71,6 +69,9 @@ bool win_may_fill(win_T *wp) return (wp->w_p_diff && diffopt_filler()) || wp->w_buffer->b_virt_line_blocks; } +/// Return the number of window lines occupied by buffer line "lnum". +/// Does not include filler lines. +/// /// @param winheight when true limit to window height int plines_win_nofill(win_T *wp, linenr_T lnum, bool winheight) { @@ -106,7 +107,7 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) if (*s == NUL) { // empty line return 1; } - col = win_linetabsize(wp, lnum, (char_u *)s, MAXCOL); + col = win_linetabsize(wp, lnum, s, MAXCOL); // If list mode is on, then the '$' at the end of the line may take up one // extra column. @@ -144,12 +145,12 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column) return lines + 1; } - char_u *line = (char_u *)ml_get_buf(wp->w_buffer, lnum, false); + char *line = ml_get_buf(wp->w_buffer, lnum, false); colnr_T col = 0; chartabsize_T cts; - init_chartabsize_arg(&cts, wp, lnum, 0, (char *)line, (char *)line); + init_chartabsize_arg(&cts, wp, lnum, 0, line, line); while (*cts.cts_ptr != NUL && --column >= 0) { cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); MB_PTR_ADV(cts.cts_ptr); @@ -232,9 +233,8 @@ int win_chartabsize(win_T *wp, char *p, colnr_T col) buf_T *buf = wp->w_buffer; if (*p == TAB && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { return tabstop_padding(col, buf->b_p_ts, buf->b_p_vts_array); - } else { - return ptr2cells(p); } + return ptr2cells(p); } /// Return the number of characters the string 's' will take on the screen, @@ -243,9 +243,9 @@ int win_chartabsize(win_T *wp, char *p, colnr_T col) /// @param s /// /// @return Number of characters the string will take on the screen. -int linetabsize(char_u *s) +int linetabsize(char *s) { - return linetabsize_col(0, (char *)s); + return linetabsize_col(0, s); } /// Like linetabsize(), but "s" starts at column "startcol". @@ -272,11 +272,11 @@ int linetabsize_col(int startcol, char *s) /// @param len /// /// @return Number of characters the string will take on the screen. -unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char_u *line, colnr_T len) +unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char *line, colnr_T len) { chartabsize_T cts; - init_chartabsize_arg(&cts, wp, lnum, 0, (char *)line, (char *)line); - for (; *cts.cts_ptr != NUL && (len == MAXCOL || cts.cts_ptr < (char *)line + len); + init_chartabsize_arg(&cts, wp, lnum, 0, line, line); + for (; *cts.cts_ptr != NUL && (len == MAXCOL || cts.cts_ptr < line + len); MB_PTR_ADV(cts.cts_ptr)) { cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); } @@ -353,7 +353,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) { win_T *wp = cts->cts_win; char *line = cts->cts_line; // start of the line - char_u *s = (char_u *)cts->cts_ptr; + char *s = cts->cts_ptr; colnr_T vcol = cts->cts_vcol; colnr_T col2; @@ -362,7 +362,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) int added; int mb_added = 0; int numberextra; - char_u *ps; + char *ps; int n; cts->cts_cur_text_width = 0; @@ -373,16 +373,16 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) if (wp->w_p_wrap) { return win_nolbr_chartabsize(cts, headp); } - return win_chartabsize(wp, (char *)s, vcol); + return win_chartabsize(wp, s, vcol); } // First get normal size, without 'linebreak' or virtual text - int size = win_chartabsize(wp, (char *)s, vcol); + int size = win_chartabsize(wp, s, vcol); if (cts->cts_has_virt_text) { // TODO(bfredl): inline virtual text } - int c = *s; + int c = (uint8_t)(*s); if (*s == TAB) { col_adj = size - 1; } @@ -391,7 +391,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) // needs a break here if (wp->w_p_lbr && vim_isbreak(c) - && !vim_isbreak((int)s[1]) + && !vim_isbreak((uint8_t)s[1]) && wp->w_p_wrap && (wp->w_width_inner != 0)) { // Count all characters from first non-blank after a blank up to next @@ -412,14 +412,14 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) for (;;) { ps = s; MB_PTR_ADV(s); - c = *s; + c = (uint8_t)(*s); if (!(c != NUL - && (vim_isbreak(c) || col2 == vcol || !vim_isbreak((int)(*ps))))) { + && (vim_isbreak(c) || col2 == vcol || !vim_isbreak((uint8_t)(*ps))))) { break; } - col2 += win_chartabsize(wp, (char *)s, col2); + col2 += win_chartabsize(wp, s, col2); if (col2 >= colmax) { // doesn't fit size = colmax - vcol + col_adj; @@ -427,7 +427,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) } } } else if ((size == 2) - && (MB_BYTE2LEN(*s) > 1) + && (MB_BYTE2LEN((uint8_t)(*s)) > 1) && wp->w_p_wrap && in_win_border(wp, vcol)) { // Count the ">" in the last column. @@ -438,9 +438,9 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) // May have to add something for 'breakindent' and/or 'showbreak' // string at start of line. // Set *headp to the size of what we add. + // Do not use 'showbreak' at the NUL after the text. added = 0; - - char *const sbr = (char *)get_showbreak_value(wp); + char *const sbr = c == NUL ? empty_option : get_showbreak_value(wp); if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && vcol != 0) { colnr_T sbrlen = 0; int numberwidth = win_col_off(wp); @@ -455,7 +455,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) vcol %= numberextra; } if (*sbr != NUL) { - sbrlen = (colnr_T)mb_charlen((char_u *)sbr); + sbrlen = (colnr_T)mb_charlen(sbr); if (vcol >= sbrlen) { vcol -= sbrlen; } @@ -491,7 +491,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) } if (wp->w_p_bri) { - added += get_breakindent_win(wp, (char_u *)line); + added += get_breakindent_win(wp, line); } size += added; |