From 2237b384e4027af7c977a4be01d792fcb790819c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 11 Jun 2023 11:29:39 +0800 Subject: vim-patch:9.0.1626: Visual area not shown when using 'showbreak' (#23978) Problem: Visual area not shown when using 'showbreak' and start of line is not visible. (Jaehwang Jung) Solution: Adjust "fromcol" for the space taken by 'showbreak'. (closes vim/vim#12514) https://github.com/vim/vim/commit/f578ca2c8f36b61ac3301fe8b59a8473c964cdc2 Co-authored-by: Bram Moolenaar --- src/nvim/drawline.c | 8 +- src/nvim/grid.c | 2 +- test/functional/legacy/051_highlight_spec.lua | 96 -------------------- test/functional/legacy/highlight_spec.lua | 122 ++++++++++++++++++++++++++ test/old/testdir/test_highlight.vim | 23 ++++- 5 files changed, 151 insertions(+), 100 deletions(-) delete mode 100644 test/functional/legacy/051_highlight_spec.lua create mode 100644 test/functional/legacy/highlight_spec.lua diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index ff14ae0e41..280c1d6994 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -92,7 +92,7 @@ typedef struct { int fromcol; ///< start of inverting int tocol; ///< end of inverting - long vcol_sbr; ///< virtual column after showbreak + colnr_T vcol_sbr; ///< virtual column after showbreak bool need_showbreak; ///< overlong line, skipping first x chars int char_attr; ///< attributes for next character @@ -832,6 +832,12 @@ static void handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv) wlv->need_showbreak = false; } wlv->vcol_sbr = wlv->vcol + mb_charlen(sbr); + + // Correct start of highlighted area for 'showbreak'. + if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr) { + wlv->fromcol = wlv->vcol_sbr; + } + // Correct end of highlighted area for 'showbreak', // required when 'linebreak' is also set. if (wlv->tocol == wlv->vcol) { diff --git a/src/nvim/grid.c b/src/nvim/grid.c index f2ceb2ac24..11cd691f22 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -540,7 +540,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol, int cle size_t skip = 0; if (wp->w_p_nu && wp->w_p_rnu) { // do not overwrite the line number, change "123 text" to - // "123>>>xt". + // "123<<') - -- FIXME(tarruda): We need to be sure the prompt is displayed before - -- continuing, or risk a race condition where some of the following input - -- is discarded resulting in test failure - screen:expect([[ - :highlight | - SpecialKey xxx ctermfg=4 | - guifg=Blue | - EndOfBuffer xxx links to NonText| - | - TermCursor xxx cterm=reverse | - gui=reverse | - TermCursorNC xxx cleared | - NonText xxx ctermfg=12 | - -- More --^ | - ]]) - feed('q') - poke_eventloop() -- wait until we're back to normal - feed_command('hi Search') - feed_command('hi Normal') - - -- Test setting colors. - -- Test clearing one color and all doesn't generate error or warning - feed_command('hi NewGroup cterm=italic ctermfg=DarkBlue ctermbg=Grey gui=NONE guifg=#00ff00 guibg=Cyan') - feed_command('hi Group2 cterm=NONE') - feed_command('hi Group3 cterm=bold') - feed_command('redir! @a') - feed_command('hi NewGroup') - feed_command('hi Group2') - feed_command('hi Group3') - feed_command('hi clear NewGroup') - feed_command('hi NewGroup') - feed_command('hi Group2') - feed_command('hi Group2 NONE') - feed_command('hi Group2') - feed_command('hi clear') - feed_command('hi Group3') - feed('') - eq('Vim(highlight):E475: Invalid argument: cterm=\'asdf', - exc_exec([[hi Crash cterm='asdf]])) - feed_command('redir END') - - -- Filter ctermfg and ctermbg, the numbers depend on the terminal - feed_command('0put a') - feed_command([[%s/ctermfg=\d*/ctermfg=2/]]) - feed_command([[%s/ctermbg=\d*/ctermbg=3/]]) - - -- Fix the fileformat - feed_command('set ff&') - feed_command('$d') - - -- Assert buffer contents. - expect([[ - - - NewGroup xxx cterm=italic - ctermfg=2 - ctermbg=3 - guifg=#00ff00 - guibg=Cyan - - Group2 xxx cleared - - Group3 xxx cterm=bold - - - NewGroup xxx cleared - - Group2 xxx cleared - - - Group2 xxx cleared - - - Group3 xxx cleared]]) - end) -end) diff --git a/test/functional/legacy/highlight_spec.lua b/test/functional/legacy/highlight_spec.lua new file mode 100644 index 0000000000..0a130f1607 --- /dev/null +++ b/test/functional/legacy/highlight_spec.lua @@ -0,0 +1,122 @@ +local Screen = require('test.functional.ui.screen') +local helpers = require('test.functional.helpers')(after_each) +local clear, feed = helpers.clear, helpers.feed +local expect = helpers.expect +local eq = helpers.eq +local poke_eventloop = helpers.poke_eventloop +local exc_exec = helpers.exc_exec +local feed_command = helpers.feed_command +local exec = helpers.exec + +before_each(clear) + +describe(':highlight', function() + it('is working', function() + local screen = Screen.new(35, 10) + screen:attach() + -- Basic test if ":highlight" doesn't crash + feed_command('set more') + feed(':highlight') + -- FIXME(tarruda): We need to be sure the prompt is displayed before + -- continuing, or risk a race condition where some of the following input + -- is discarded resulting in test failure + screen:expect([[ + :highlight | + SpecialKey xxx ctermfg=4 | + guifg=Blue | + EndOfBuffer xxx links to NonText| + | + TermCursor xxx cterm=reverse | + gui=reverse | + TermCursorNC xxx cleared | + NonText xxx ctermfg=12 | + -- More --^ | + ]]) + feed('q') + poke_eventloop() -- wait until we're back to normal + feed_command('hi Search') + feed_command('hi Normal') + + -- Test setting colors. + -- Test clearing one color and all doesn't generate error or warning + feed_command('hi NewGroup cterm=italic ctermfg=DarkBlue ctermbg=Grey gui=NONE guifg=#00ff00 guibg=Cyan') + feed_command('hi Group2 cterm=NONE') + feed_command('hi Group3 cterm=bold') + feed_command('redir! @a') + feed_command('hi NewGroup') + feed_command('hi Group2') + feed_command('hi Group3') + feed_command('hi clear NewGroup') + feed_command('hi NewGroup') + feed_command('hi Group2') + feed_command('hi Group2 NONE') + feed_command('hi Group2') + feed_command('hi clear') + feed_command('hi Group3') + feed('') + eq('Vim(highlight):E475: Invalid argument: cterm=\'asdf', + exc_exec([[hi Crash cterm='asdf]])) + feed_command('redir END') + + -- Filter ctermfg and ctermbg, the numbers depend on the terminal + feed_command('0put a') + feed_command([[%s/ctermfg=\d*/ctermfg=2/]]) + feed_command([[%s/ctermbg=\d*/ctermbg=3/]]) + + -- Fix the fileformat + feed_command('set ff&') + feed_command('$d') + + -- Assert buffer contents. + expect([[ + + + NewGroup xxx cterm=italic + ctermfg=2 + ctermbg=3 + guifg=#00ff00 + guibg=Cyan + + Group2 xxx cleared + + Group3 xxx cterm=bold + + + NewGroup xxx cleared + + Group2 xxx cleared + + + Group2 xxx cleared + + + Group3 xxx cleared]]) + end) +end) + +describe('Visual selection highlight', function() + -- oldtest: Test_visual_sbr() + it("when 'showbreak' is set", function() + local screen = Screen.new(60, 6) + screen:set_default_attr_ids({ + [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + [1] = {background = Screen.colors.LightGrey}, -- Visual + [2] = {bold = true}, -- ModeMsg + }) + screen:attach() + exec([[ + set showbreak=> + call setline(1, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.') + exe "normal! z1\" + ]]) + feed('v$') + screen:expect([[ + {0:>}{1:n, no sea takimata sanctus est Lorem ipsum dolor sit amet.}^ | + | + | + | + | + {2:-- VISUAL --} | + ]]) + end) +end) diff --git a/test/old/testdir/test_highlight.vim b/test/old/testdir/test_highlight.vim index 8a102f2e65..8ed03732c2 100644 --- a/test/old/testdir/test_highlight.vim +++ b/test/old/testdir/test_highlight.vim @@ -698,7 +698,7 @@ func Test_colorcolumn_sbr() let lines =<< trim END call setline(1, 'The quick brown fox jumped over the lazy dogs') END - call writefile(lines, 'Xtest_colorcolumn_srb') + call writefile(lines, 'Xtest_colorcolumn_srb', 'D') let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40}) call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\") call TermWait(buf) @@ -706,7 +706,26 @@ func Test_colorcolumn_sbr() " clean up call StopVimInTerminal(buf) - call delete('Xtest_colorcolumn_srb') +endfunc + +func Test_visual_sbr() + CheckScreendump + + " check Visual highlight when 'showbreak' is set + let lines =<< trim END + set showbreak=> + call setline(1, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.') + exe "normal! z1\" + END + call writefile(lines, 'Xtest_visual_sbr', 'D') + let buf = RunVimInTerminal('-S Xtest_visual_sbr', {'rows': 6,'columns': 60}) + + call term_sendkeys(buf, "v$") + call VerifyScreenDump(buf, 'Test_visual_sbr_1', {}) + + " clean up + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) endfunc " This test must come before the Test_cursorline test, as it appears this -- cgit