aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/screen.c11
-rw-r--r--src/nvim/testdir/test_display.vim37
-rw-r--r--test/functional/legacy/display_spec.lua31
-rw-r--r--test/functional/legacy/visual_mode_spec.lua42
4 files changed, 116 insertions, 5 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 3503348049..7c42f29a90 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -899,11 +899,12 @@ static void win_update(win_T *wp)
|| type == INVERTED || type == INVERTED_ALL)
&& !wp->w_botfill && !wp->w_old_botfill
) {
- if (mod_top != 0 && wp->w_topline == mod_top) {
- /*
- * w_topline is the first changed line, the scrolling will be done
- * further down.
- */
+ if (mod_top != 0
+ && wp->w_topline == mod_top
+ && (!wp->w_lines[0].wl_valid
+ || wp->w_topline <= wp->w_lines[0].wl_lnum)) {
+ // w_topline is the first changed line and window is not scrolled,
+ // the scrolling from changed lines will be done further down.
} else if (wp->w_lines[0].wl_valid
&& (wp->w_topline < wp->w_lines[0].wl_lnum
|| (wp->w_topline == wp->w_lines[0].wl_lnum
diff --git a/src/nvim/testdir/test_display.vim b/src/nvim/testdir/test_display.vim
index 429253a863..e853b046dc 100644
--- a/src/nvim/testdir/test_display.vim
+++ b/src/nvim/testdir/test_display.vim
@@ -184,3 +184,40 @@ func Test_scroll_CursorLineNr_update()
call StopVimInTerminal(buf)
call delete(filename)
endfunc
+
+" Test for scrolling that modifies buffer during visual block
+func Test_visual_block_scroll()
+ " See test/functional/legacy/visual_mode_spec.lua
+ CheckScreendump
+
+ let lines =<< trim END
+ source $VIMRUNTIME/plugin/matchparen.vim
+ set scrolloff=1
+ call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
+ call cursor(5, 1)
+ END
+
+ let filename = 'Xvisualblockmodifiedscroll'
+ call writefile(lines, filename)
+
+ let buf = RunVimInTerminal('-S '.filename, #{rows: 7})
+ call term_sendkeys(buf, "V\<C-D>\<C-D>")
+
+ call VerifyScreenDump(buf, 'Test_display_visual_block_scroll', {})
+
+ call StopVimInTerminal(buf)
+ call delete(filename)
+endfunc
+
+func Test_display_scroll_at_topline()
+ " See test/functional/legacy/display_spec.lua
+ CheckScreendump
+
+ let buf = RunVimInTerminal('', #{cols: 20})
+ call term_sendkeys(buf, ":call setline(1, repeat('a', 21))\<CR>")
+ call term_wait(buf)
+ call term_sendkeys(buf, "O\<Esc>")
+ call VerifyScreenDump(buf, 'Test_display_scroll_at_topline', #{rows: 4})
+
+ call StopVimInTerminal(buf)
+endfunc
diff --git a/test/functional/legacy/display_spec.lua b/test/functional/legacy/display_spec.lua
new file mode 100644
index 0000000000..aafcda67dc
--- /dev/null
+++ b/test/functional/legacy/display_spec.lua
@@ -0,0 +1,31 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local wait = helpers.wait
+local feed = helpers.feed
+local feed_command = helpers.feed_command
+
+describe('display', function()
+ local screen
+
+ it('scroll when modified at topline', function()
+ clear()
+ screen = Screen.new(20, 4)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true},
+ })
+
+ feed_command([[call setline(1, repeat('a', 21))]])
+ wait()
+ feed('O')
+ screen:expect([[
+ ^ |
+ aaaaaaaaaaaaaaaaaaaa|
+ a |
+ {1:-- INSERT --} |
+ ]])
+ end)
+end)
+
diff --git a/test/functional/legacy/visual_mode_spec.lua b/test/functional/legacy/visual_mode_spec.lua
new file mode 100644
index 0000000000..c8e83ed649
--- /dev/null
+++ b/test/functional/legacy/visual_mode_spec.lua
@@ -0,0 +1,42 @@
+-- Test visual line mode selection redraw after scrolling
+
+local helpers = require('test.functional.helpers')(after_each)
+
+local Screen = require('test.functional.ui.screen')
+local call = helpers.call
+local clear = helpers.clear
+local feed = helpers.feed
+local feed_command = helpers.feed_command
+local funcs = helpers.funcs
+local meths = helpers.meths
+local eq = helpers.eq
+
+describe('visual line mode', function()
+ local screen
+
+ it('redraws properly after scrolling with matchparen loaded and scrolloff=1', function()
+ clear{args={'-u', 'NORC'}}
+ screen = Screen.new(30, 7)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true},
+ [2] = {background = Screen.colors.LightGrey},
+ })
+
+ eq(1, meths.get_var('loaded_matchparen'))
+ feed_command('set scrolloff=1')
+ funcs.setline(1, {'a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'})
+ call('cursor', 5, 1)
+
+ feed('V<c-d><c-d>')
+ screen:expect([[
+ {2:{} |
+ {2:}} |
+ {2:{} |
+ {2:f} |
+ ^g |
+ } |
+ {1:-- VISUAL LINE --} |
+ ]])
+ end)
+end)