patch 8.1.1713: highlighting cursor line only works with popup_menu()
Problem: Highlighting cursor line only works with popup_menu().
Solution: Add the "cursorline" property. (Naruhiko Nishino, closes #4671)
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 740ac61..0ec901c 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -1921,4 +1921,176 @@
call delete('XtestPopupMenuScroll')
endfunc
+func Test_popup_menu_filter()
+ if !CanRunVimInTerminal()
+ throw 'Skipped: cannot make screendumps'
+ endif
+
+ let lines =<< trim END
+ function! MyFilter(winid, key) abort
+ if a:key == "0"
+ call win_execute(a:winid, "call setpos('.', [0, 1, 1, 0])")
+ return 1
+ endif
+ if a:key == "G"
+ call win_execute(a:winid, "call setpos('.', [0, line('$'), 1, 0])")
+ return 1
+ endif
+ if a:key == "j"
+ call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0])")
+ return 1
+ endif
+ if a:key == "k"
+ call win_execute(a:winid, "call setpos('.', [0, line('.') - 1, 1, 0])")
+ return 1
+ endif
+ if a:key == 'x'
+ call popup_close(a:winid)
+ return 1
+ endif
+ return 0
+ endfunction
+ call popup_menu(['111', '222', '333', '444', '555', '666', '777', '888', '999'], #{
+ \ maxheight : 3,
+ \ filter : 'MyFilter'
+ \ })
+ END
+ call writefile(lines, 'XtestPopupMenuFilter')
+ let buf = RunVimInTerminal('-S XtestPopupMenuFilter', #{rows: 10})
+
+ call term_sendkeys(buf, "j")
+ call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_1', {})
+
+ call term_sendkeys(buf, "k")
+ call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_2', {})
+
+ call term_sendkeys(buf, "G")
+ call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_3', {})
+
+ call term_sendkeys(buf, "0")
+ call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_4', {})
+
+ call term_sendkeys(buf, "x")
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('XtestPopupMenuFilter')
+endfunc
+
+func Test_popup_cursorline()
+ if !CanRunVimInTerminal()
+ throw 'Skipped: cannot make screendumps'
+ endif
+
+ let winid = popup_create('some text', {})
+ call assert_equal(0, popup_getoptions(winid).cursorline)
+ call popup_close(winid)
+
+ let winid = popup_create('some text', #{ cursorline: 1, })
+ call assert_equal(1, popup_getoptions(winid).cursorline)
+ call popup_close(winid)
+
+ let winid = popup_create('some text', #{ cursorline: 0, })
+ call assert_equal(0, popup_getoptions(winid).cursorline)
+ call popup_close(winid)
+
+ let winid = popup_menu('some text', {})
+ call assert_equal(1, popup_getoptions(winid).cursorline)
+ call popup_close(winid)
+
+ let winid = popup_menu('some text', #{ cursorline: 1, })
+ call assert_equal(1, popup_getoptions(winid).cursorline)
+ call popup_close(winid)
+
+ let winid = popup_menu('some text', #{ cursorline: 0, })
+ call assert_equal(0, popup_getoptions(winid).cursorline)
+ call popup_close(winid)
+
+ " ---------
+ " Pattern 1
+ " ---------
+ let lines =<< trim END
+ call popup_create(['111', '222', '333'], #{ cursorline : 0 })
+ END
+ call writefile(lines, 'XtestPopupCursorLine')
+ let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
+ call VerifyScreenDump(buf, 'Test_popupwin_cursorline_1', {})
+ call term_sendkeys(buf, ":call popup_clear()\<cr>")
+ call StopVimInTerminal(buf)
+
+ " ---------
+ " Pattern 2
+ " ---------
+ let lines =<< trim END
+ call popup_create(['111', '222', '333'], #{ cursorline : 1 })
+ END
+ call writefile(lines, 'XtestPopupCursorLine')
+ let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
+ call VerifyScreenDump(buf, 'Test_popupwin_cursorline_2', {})
+ call term_sendkeys(buf, ":call popup_clear()\<cr>")
+ call StopVimInTerminal(buf)
+
+ " ---------
+ " Pattern 3
+ " ---------
+ let lines =<< trim END
+ function! MyFilter(winid, key) abort
+ if a:key == "j"
+ call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
+ return 1
+ endif
+ if a:key == 'x'
+ call popup_close(a:winid)
+ return 1
+ endif
+ return 0
+ endfunction
+ call popup_menu(['111', '222', '333'], #{
+ \ cursorline : 0,
+ \ maxheight : 2,
+ \ filter : 'MyFilter',
+ \ })
+ END
+ call writefile(lines, 'XtestPopupCursorLine')
+ let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
+ call VerifyScreenDump(buf, 'Test_popupwin_cursorline_3', {})
+ call term_sendkeys(buf, "j")
+ call term_sendkeys(buf, "j")
+ call VerifyScreenDump(buf, 'Test_popupwin_cursorline_4', {})
+ call term_sendkeys(buf, "x")
+ call StopVimInTerminal(buf)
+
+ " ---------
+ " Pattern 4
+ " ---------
+ let lines =<< trim END
+ function! MyFilter(winid, key) abort
+ if a:key == "j"
+ call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
+ return 1
+ endif
+ if a:key == 'x'
+ call popup_close(a:winid)
+ return 1
+ endif
+ return 0
+ endfunction
+ call popup_menu(['111', '222', '333'], #{
+ \ cursorline : 1,
+ \ maxheight : 2,
+ \ filter : 'MyFilter',
+ \ })
+ END
+ call writefile(lines, 'XtestPopupCursorLine')
+ let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
+ call VerifyScreenDump(buf, 'Test_popupwin_cursorline_5', {})
+ call term_sendkeys(buf, "j")
+ call term_sendkeys(buf, "j")
+ call VerifyScreenDump(buf, 'Test_popupwin_cursorline_6', {})
+ call term_sendkeys(buf, "x")
+ call StopVimInTerminal(buf)
+
+ call delete('XtestPopupCursorLine')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab