aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/drawline.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-03-13 15:00:43 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-03-14 13:09:54 +0800
commit090d1fd0b86897d2f5a80a600becf1525398ef30 (patch)
tree94b10da1cf7d680654d6b597dae2c5bd0686b0be /src/nvim/drawline.c
parent3502aa63f0f4ea8d8982aea81a819424e71029bc (diff)
downloadrneovim-090d1fd0b86897d2f5a80a600becf1525398ef30.tar.gz
rneovim-090d1fd0b86897d2f5a80a600becf1525398ef30.tar.bz2
rneovim-090d1fd0b86897d2f5a80a600becf1525398ef30.zip
vim-patch:9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()
Problem: More code can use ml_get_buf_len() instead of STRLEN(). Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not set ml_line_textlen in ml_replace_len() if "has_props" is set, because "len_arg" also includes the size of text properties in that case. (zeertzjq) closes: vim/vim#14183 https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b
Diffstat (limited to 'src/nvim/drawline.c')
-rw-r--r--src/nvim/drawline.c69
1 files changed, 26 insertions, 43 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 8b6c3d58b2..4eaea4c6be 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -850,43 +850,6 @@ static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t
}
}
-static colnr_T get_trailcol(win_T *wp, const char *ptr, const char *line)
-{
- colnr_T trailcol = MAXCOL;
- // find start of trailing whitespace
- if (wp->w_p_lcs_chars.trail) {
- trailcol = (colnr_T)strlen(ptr);
- while (trailcol > 0 && ascii_iswhite(ptr[trailcol - 1])) {
- trailcol--;
- }
- trailcol += (colnr_T)(ptr - line);
- }
-
- return trailcol;
-}
-
-static colnr_T get_leadcol(win_T *wp, const char *ptr, const char *line)
-{
- colnr_T leadcol = 0;
-
- // find end of leading whitespace
- if (wp->w_p_lcs_chars.lead || wp->w_p_lcs_chars.leadmultispace != NULL) {
- leadcol = 0;
- while (ascii_iswhite(ptr[leadcol])) {
- leadcol++;
- }
- if (ptr[leadcol] == NUL) {
- // in a line full of spaces all of them are treated as trailing
- leadcol = 0;
- } else {
- // keep track of the first column not filled with spaces
- leadcol += (colnr_T)(ptr - line + 1);
- }
- }
-
- return leadcol;
-}
-
/// Start a screen line at column zero.
static void win_line_start(win_T *wp, winlinevars_T *wlv)
{
@@ -1298,17 +1261,17 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
nextlinecol = MAXCOL;
nextline_idx = 0;
} else {
- const size_t line_len = strlen(line);
+ const colnr_T line_len = ml_get_buf_len(wp->w_buffer, lnum);
if (line_len < SPWORDLEN) {
// Short line, use it completely and append the start of the
// next line.
nextlinecol = 0;
- memmove(nextline, line, line_len);
+ memmove(nextline, line, (size_t)line_len);
STRMOVE(nextline + line_len, nextline + SPWORDLEN);
- nextline_idx = (int)line_len + 1;
+ nextline_idx = line_len + 1;
} else {
// Long line, use only the last SPWORDLEN bytes.
- nextlinecol = (int)line_len - SPWORDLEN;
+ nextlinecol = line_len - SPWORDLEN;
memmove(nextline, line + nextlinecol, SPWORDLEN);
nextline_idx = SPWORDLEN + 1;
}
@@ -1336,8 +1299,28 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
|| wp->w_p_lcs_chars.nbsp) {
extra_check = true;
}
- trailcol = get_trailcol(wp, ptr, line);
- leadcol = get_leadcol(wp, ptr, line);
+ // find start of trailing whitespace
+ if (wp->w_p_lcs_chars.trail) {
+ trailcol = ml_get_buf_len(wp->w_buffer, lnum);
+ while (trailcol > 0 && ascii_iswhite(ptr[trailcol - 1])) {
+ trailcol--;
+ }
+ trailcol += (colnr_T)(ptr - line);
+ }
+ // find end of leading whitespace
+ if (wp->w_p_lcs_chars.lead || wp->w_p_lcs_chars.leadmultispace != NULL) {
+ leadcol = 0;
+ while (ascii_iswhite(ptr[leadcol])) {
+ leadcol++;
+ }
+ if (ptr[leadcol] == NUL) {
+ // in a line full of spaces all of them are treated as trailing
+ leadcol = 0;
+ } else {
+ // keep track of the first column not filled with spaces
+ leadcol += (colnr_T)(ptr - line + 1);
+ }
+ }
}
// 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the