From a01f8de1f065a4112dc9d7bd33651fd9c026d139 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sun, 21 May 2023 03:13:05 +0200 Subject: [PATCH] fix(redraw): multibyte characters are wrapped at the end of a line Problem: Multibyte characters may be wrapped at the end of a line when 'statuscolumn' and 'spell' are set. Solution: Update line pointerdiff "v" before fetching the line pointer after evaluating 'statuscolumn'. (cherry picked from commit 5fa5fff184ef778bf2db6221702eaf612dc43db5) --- src/nvim/drawline.c | 3 ++- test/functional/ui/statuscolumn_spec.lua | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 0b36102806..fffe4fcac9 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -2,7 +2,7 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // drawline.c: Functions for drawing window lines on the screen. -// This is the middle level, drawscreen.c is the top and grid.c/screen.c the lower level. +// This is the middle level, drawscreen.c is the top and grid.c the lower level. #include #include @@ -1590,6 +1590,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, // Draw the 'statuscolumn' if option is set. if (statuscol.draw) { if (statuscol.textp == NULL) { + v = (ptr - line); 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. diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua index 3b41d3684a..3d68246ba9 100644 --- a/test/functional/ui/statuscolumn_spec.lua +++ b/test/functional/ui/statuscolumn_spec.lua @@ -674,4 +674,16 @@ describe('statuscolumn', function() ]]) eq(2, eval('g:stcnr')) end) + + it('does not wrap multibyte characters at the end of a line', function() + screen:try_resize(33, 4) + command([[set spell stc=%l\ ]]) + command('call setline(8, "This is a line that contains ᶏ multibyte character.")') + screen:expect([[ + 8 ^This is a line that contains ᶏ| + multibyte character. | + 9 aaaaa | + | + ]]) + end) end)