diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2020-02-16 23:18:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-16 23:18:24 -0800 |
commit | 03f245c0b810fa2ff980bd3bf2530d94fd0f05d3 (patch) | |
tree | dbbd77ecb94314d118f0a9a9a001d33ba1b74053 /src/nvim/buffer.c | |
parent | 0c5d2ffebe92e710ca57d4e3f0b0789ccc369660 (diff) | |
parent | 1ce4b3c9a7420227c3ecffab782cb8da732998f5 (diff) | |
download | rneovim-03f245c0b810fa2ff980bd3bf2530d94fd0f05d3.tar.gz rneovim-03f245c0b810fa2ff980bd3bf2530d94fd0f05d3.tar.bz2 rneovim-03f245c0b810fa2ff980bd3bf2530d94fd0f05d3.zip |
Merge #11873 from janlazo/vim-8.1.0786
vim-patch:8.0.1660,8.1.{43,786,1201,2129,2131,2187,2223,2259},8.2.{241,267}
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r-- | src/nvim/buffer.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 790609ab94..c2573cf942 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3397,14 +3397,27 @@ int build_stl_str_hl( fillchar = '-'; } + // The cursor in windows other than the current one isn't always + // up-to-date, esp. because of autocommands and timers. + linenr_T lnum = wp->w_cursor.lnum; + if (lnum > wp->w_buffer->b_ml.ml_line_count) { + lnum = wp->w_buffer->b_ml.ml_line_count; + wp->w_cursor.lnum = lnum; + } + // Get line & check if empty (cursorpos will show "0-1"). - char_u *line_ptr = ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, false); + const char_u *line_ptr = ml_get_buf(wp->w_buffer, lnum, false); bool empty_line = (*line_ptr == NUL); // Get the byte value now, in case we need it below. This is more // efficient than making a copy of the line. int byteval; - if (wp->w_cursor.col > (colnr_T)STRLEN(line_ptr)) { + const size_t len = STRLEN(line_ptr); + if (wp->w_cursor.col > (colnr_T)len) { + // Line may have changed since checking the cursor column, or the lnum + // was adjusted above. + wp->w_cursor.col = (colnr_T)len; + wp->w_cursor.coladd = 0; byteval = 0; } else { byteval = utf_ptr2char(line_ptr + wp->w_cursor.col); |