From d5bc62a5ce6033581b98103c986e01fe91f0c454 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 7 Oct 2020 19:47:36 -0400 Subject: [PATCH 1/5] vim-patch:8.1.1717: last char in menu popup window highlighted Problem: Last char in menu popup window highlighted. Solution: Do not highlight an extra character twice. https://github.com/vim/vim/commit/f914a33c9c8ec5c30da684a4a16edad3e0224f0a N/A patches for version.c: vim-patch:8.1.0746: highlighting not updated with conceal and 'cursorline' Problem: Highlighting not updated with conceal and 'cursorline'. (Jason Franklin) Solution: Do not use a zero line number. Check if 'conceallevel' is set for the current window. https://github.com/vim/vim/commit/bbee8d5122b159683b3f52eddd0da85fcf1fcbfd --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 7c42f29a90..ea2b14c326 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3690,7 +3690,7 @@ win_line ( } // At end of the text line or just after the last character. - if (c == NUL) { + if (c == NUL && eol_hl_off == 0) { long prevcol = (long)(ptr - line) - 1; // we're not really at that column when skipping some text From 910bbc3cca796f7fa941e0f6176cd0061de0e01c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 8 Oct 2020 07:18:42 -0400 Subject: [PATCH 2/5] vim-patch:8.1.2294: cursor pos wrong with concealing and search causes a scroll Problem: Cursor position wrong when characters are concealed and asearch causes a scroll. Solution: Fix the cursor column in a concealed line after window scroll. (closes vim/vim#5215, closes vim/vim#5012) https://github.com/vim/vim/commit/cbee635eee3007db97646ddb9f211a1d4966eb2a --- src/nvim/screen.c | 51 ++++++++++++++++++---- src/nvim/testdir/test_matchadd_conceal.vim | 45 +++++++++++++++++-- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/src/nvim/screen.c b/src/nvim/screen.c index ea2b14c326..a75b146024 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -698,8 +698,10 @@ static void win_update(win_T *wp) int didline = FALSE; /* if TRUE, we finished the last line */ int i; long j; - static int recursive = FALSE; /* being called recursively */ - int old_botline = wp->w_botline; + static bool recursive = false; // being called recursively + const linenr_T old_botline = wp->w_botline; + const int old_wrow = wp->w_wrow; + const int old_wcol = wp->w_wcol; // Remember what happened to the previous line. #define DID_NONE 1 // didn't update a line #define DID_LINE 2 // updated a normal line @@ -1639,18 +1641,51 @@ static void win_update(win_T *wp) wp->w_valid |= VALID_BOTLINE; wp->w_viewport_invalid = true; if (wp == curwin && wp->w_botline != old_botline && !recursive) { - recursive = TRUE; + const linenr_T old_topline = wp->w_topline; + const int new_wcol = wp->w_wcol; + recursive = true; curwin->w_valid &= ~VALID_TOPLINE; - update_topline(); /* may invalidate w_botline again */ - if (must_redraw != 0) { - /* Don't update for changes in buffer again. */ + update_topline(); // may invalidate w_botline again + + if (old_wcol != new_wcol + && (wp->w_valid & (VALID_WCOL|VALID_WROW)) + != (VALID_WCOL|VALID_WROW)) { + // A win_line() call applied a fix to screen cursor column to + // accomodate concealment of cursor line, but in this call to + // update_topline() the cursor's row or column got invalidated. + // If they are left invalid, setcursor() will recompute them + // but there won't be any further win_line() call to re-fix the + // column and the cursor will end up misplaced. So we call + // cursor validation now and reapply the fix again (or call + // win_line() to do it for us). + validate_cursor(); + if (wp->w_wcol == old_wcol + && wp->w_wrow == old_wrow + && old_topline == wp->w_topline) { + wp->w_wcol = new_wcol; + } else { + redrawWinline(wp, wp->w_cursor.lnum); + } + } + // New redraw either due to updated topline or due to wcol fix. + if (wp->w_redr_type != 0) { + // Don't update for changes in buffer again. i = curbuf->b_mod_set; curbuf->b_mod_set = false; + j = curbuf->b_mod_xlines; + curbuf->b_mod_xlines = 0; win_update(curwin); - must_redraw = 0; curbuf->b_mod_set = i; + curbuf->b_mod_xlines = j; } - recursive = FALSE; + // Other windows might have w_redr_type raised in update_topline(). + must_redraw = 0; + FOR_ALL_WINDOWS_IN_TAB(wwp, curtab) { + if (wwp->w_redr_type > must_redraw) { + must_redraw = wwp->w_redr_type; + } + } + recursive = false; } } diff --git a/src/nvim/testdir/test_matchadd_conceal.vim b/src/nvim/testdir/test_matchadd_conceal.vim index b918525dbc..cb70b2857f 100644 --- a/src/nvim/testdir/test_matchadd_conceal.vim +++ b/src/nvim/testdir/test_matchadd_conceal.vim @@ -1,9 +1,11 @@ " Test for matchadd() and conceal feature -if !has('conceal') - finish -endif + +source check.vim +CheckFeature conceal source shared.vim +source term_util.vim +source view_util.vim function! Test_simple_matchadd() new @@ -273,3 +275,40 @@ function! Test_matchadd_and_syn_conceal() call assert_notequal(screenattr(1, 11) , screenattr(1, 12)) call assert_equal(screenattr(1, 11) , screenattr(1, 32)) endfunction + +func Test_cursor_column_in_concealed_line_after_window_scroll() + CheckRunVimInTerminal + + " Test for issue #5012 fix. + " For a concealed line with cursor, there should be no window's cursor + " position invalidation during win_update() after scrolling attempt that is + " not successful and no real topline change happens. The invalidation would + " cause a window's cursor position recalc outside of win_line() where it's + " not possible to take conceal into account. + let lines =<< trim END + 3split + let m = matchadd('Conceal', '=') + setl conceallevel=2 concealcursor=nc + normal gg + "==expr== + END + call writefile(lines, 'Xcolesearch') + let buf = RunVimInTerminal('Xcolesearch', {}) + + " Jump to something that is beyond the bottom of the window, + " so there's a scroll down. + call term_sendkeys(buf, ":so %\") + call term_sendkeys(buf, "/expr\") + call term_wait(buf) + + " Are the concealed parts of the current line really hidden? + let cursor_row = term_scrape(buf, '.')->map({_, e -> e.chars})->join('') + call assert_equal('"expr', cursor_row) + + " BugFix check: Is the window's cursor column properly updated for hidden + " parts of the current line? + call assert_equal(2, term_getcursor(buf)[1]) + + call StopVimInTerminal(buf) + call delete('Xcolesearch') +endfunc From 818e794f12171ab0fd62152e7d197da7bc43535f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 8 Oct 2020 07:51:29 -0400 Subject: [PATCH 3/5] vim-patch:8.1.2303: cursor in wrong position after horizontal scroll Problem: Cursor in wrong position after horizontal scroll. Solution: Set w_valid_leftcol. (closes vim/vim#5214, closes vim/vim#5224) https://github.com/vim/vim/commit/08f23636aef595f4cc061dfee8248dca97df16b3 --- src/nvim/move.c | 3 +++ src/nvim/testdir/test_matchadd_conceal.vim | 28 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/nvim/move.c b/src/nvim/move.c index 8a8a639a52..4e9d42ed7b 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -943,6 +943,9 @@ void curs_columns( redraw_later(SOME_VALID); } + // now w_leftcol is valid, avoid check_cursor_moved() thinking otherwise + curwin->w_valid_leftcol = curwin->w_leftcol; + curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; } diff --git a/src/nvim/testdir/test_matchadd_conceal.vim b/src/nvim/testdir/test_matchadd_conceal.vim index cb70b2857f..ec9f4d5575 100644 --- a/src/nvim/testdir/test_matchadd_conceal.vim +++ b/src/nvim/testdir/test_matchadd_conceal.vim @@ -312,3 +312,31 @@ func Test_cursor_column_in_concealed_line_after_window_scroll() call StopVimInTerminal(buf) call delete('Xcolesearch') endfunc + +func Test_cursor_column_in_concealed_line_after_leftcol_change() + CheckRunVimInTerminal + + " Test for issue #5214 fix. + let lines =<< trim END + 0put = 'ab' .. repeat('-', &columns) .. 'c' + call matchadd('Conceal', '-') + set nowrap ss=0 cole=3 cocu=n + END + call writefile(lines, 'Xcurs-columns') + let buf = RunVimInTerminal('-S Xcurs-columns', {}) + + " Go to the end of the line (3 columns beyond the end of the screen). + " Horizontal scroll would center the cursor in the screen line, but conceal + " makes it go to screen column 1. + call term_sendkeys(buf, "$") + call term_wait(buf) + + " Are the concealed parts of the current line really hidden? + call assert_equal('c', term_getline(buf, '.')) + + " BugFix check: Is the window's cursor column properly updated for conceal? + call assert_equal(1, term_getcursor(buf)[1]) + + call StopVimInTerminal(buf) + call delete('Xcurs-columns') +endfunc From 56bb5993d99592a9a45852e7e7f0e1c64257baf4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 8 Oct 2020 07:54:46 -0400 Subject: [PATCH 4/5] vim-patch:8.1.2405: matchadd_conceal test fails under valgrind Problem: matchadd_conceal test fails under valgrind. Solution: Use WaitForAssert() and wait a bit longer. https://github.com/vim/vim/commit/1f9a028def327bd9bbfef375cb1283cd51e04678 --- src/nvim/testdir/test_matchadd_conceal.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nvim/testdir/test_matchadd_conceal.vim b/src/nvim/testdir/test_matchadd_conceal.vim index ec9f4d5575..393e183ddb 100644 --- a/src/nvim/testdir/test_matchadd_conceal.vim +++ b/src/nvim/testdir/test_matchadd_conceal.vim @@ -294,12 +294,14 @@ func Test_cursor_column_in_concealed_line_after_window_scroll() END call writefile(lines, 'Xcolesearch') let buf = RunVimInTerminal('Xcolesearch', {}) + call term_wait(buf, 100) " Jump to something that is beyond the bottom of the window, " so there's a scroll down. call term_sendkeys(buf, ":so %\") + call term_wait(buf, 100) call term_sendkeys(buf, "/expr\") - call term_wait(buf) + call term_wait(buf, 100) " Are the concealed parts of the current line really hidden? let cursor_row = term_scrape(buf, '.')->map({_, e -> e.chars})->join('') @@ -332,7 +334,7 @@ func Test_cursor_column_in_concealed_line_after_leftcol_change() call term_wait(buf) " Are the concealed parts of the current line really hidden? - call assert_equal('c', term_getline(buf, '.')) + call WaitForAssert({-> assert_equal('c', term_getline(buf, '.'))}) " BugFix check: Is the window's cursor column properly updated for conceal? call assert_equal(1, term_getcursor(buf)[1]) From 2bfe2018d652e4bbf444795b2544d7d2af4e7243 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 8 Oct 2020 18:52:18 -0400 Subject: [PATCH 5/5] vim-patch:8.2.0007: popup menu positioned wrong with folding in two tabs Problem: Popup menu positioned wrong with folding in two tabs. Solution: Update the cursor line height. (closes vim/vim#5353) https://github.com/vim/vim/commit/09dd2bb3364cc8fb5a8f2507bc2f4ceba481db3d --- src/nvim/move.c | 2 +- src/nvim/popupmnu.c | 1 + src/nvim/testdir/test_ins_complete.vim | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/nvim/move.c b/src/nvim/move.c index 4e9d42ed7b..e2a304efa5 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -641,7 +641,7 @@ void validate_virtcol_win(win_T *wp) /* * Validate curwin->w_cline_height only. */ -static void validate_cheight(void) +void validate_cheight(void) { check_cursor_moved(curwin); if (!(curwin->w_valid & VALID_CHEIGHT)) { diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index c712762bdf..3beada5bc9 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -226,6 +226,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, pum_above = false; // Leave two lines of context if possible + validate_cheight(); if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) { context_lines = 3; } else { diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 1c275d5bd1..1339a9f25d 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -1,3 +1,5 @@ +source screendump.vim +source check.vim " Test for insert expansion func Test_ins_complete() @@ -338,3 +340,27 @@ func Test_compl_in_cmdwin() delcom GetInput set wildmenu& wildchar& endfunc + +func Test_pum_with_folds_two_tabs() + CheckScreendump + + let lines =<< trim END + set fdm=marker + call setline(1, ['" x {{{1', '" a some text']) + call setline(3, range(&lines)->map({_, val -> '" a' .. val})) + norm! zm + tab sp + call feedkeys('2Gzv', 'xt') + call feedkeys("0fa", 'xt') + END + + call writefile(lines, 'Xpumscript') + let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10}) + call term_wait(buf, 100) + call term_sendkeys(buf, "a\") + call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) + call delete('Xpumscript') +endfunc