From b7d59649acf43c76cc72b25c04bcae926a40b4fe Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 12:23:04 +0800 Subject: fix(redraw): get the line again after evaluating something --- src/nvim/drawline.c | 9 +++++++++ test/functional/ui/statuscolumn_spec.lua | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index a2ae828f7e..a46f383f64 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -1507,6 +1507,11 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (statuscol.draw) { if (statuscol.textp == NULL) { get_statuscol_str(wp, lnum, wlv.row - startrow - wlv.filler_lines, &statuscol); + if (!end_fill) { + // Get the line again as evaluating 'statuscolumn' may free it. + line = ml_get_buf(wp->w_buffer, lnum, false); + ptr = line + v; + } if (wp->w_redr_statuscol) { break; } @@ -1585,6 +1590,10 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, wlv.c_extra = NUL; wlv.c_final = NUL; wlv.p_extra[wlv.n_extra] = NUL; + + // Get the line again as evaluating 'foldtext' may free it. + line = ml_get_buf(wp->w_buffer, lnum, false); + ptr = line + v; } if (wlv.draw_state == WL_LINE diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index f997546c7c..08b5d1913b 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -375,6 +375,28 @@ describe('statuscolumn', function() {1:wrapped 1 9}aaaaaaaa | | ]]) + -- Also test virt_lines at the end of buffer + exec_lua([[ + local ns = vim.api.nvim_create_namespace("ns") + vim.api.nvim_buf_set_extmark(0, ns, 15, 0, { virt_lines = {{{"END", ""}}} }) + ]]) + feed('Gzz') + screen:expect([[ + {1:buffer 0 13}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1:wrapped 1 13}aaaaaaaaa | + {1:buffer 0 14}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1:wrapped 1 14}aaaaaaaaa | + {1:buffer 0 15}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| + {1:wrapped 1 15}aaaaaaaaa | + {4:buffer 0 16}{5:^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| + {4:wrapped 1 16}{5:aaaaaaaaa }| + {1:virtual-1 16}END | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) end) it("works with 'statuscolumn' clicks", function() -- cgit