comparison src/testdir/test_popupwin.vim @ 17429:6e756ad5ef1a v8.1.1713

patch 8.1.1713: highlighting cursor line only works with popup_menu() commit https://github.com/vim/vim/commit/df9c6cad8cc318e26e99c3b055f0788e7d6582de Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 18 13:46:42 2019 +0200 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 https://github.com/vim/vim/issues/4671)
author Bram Moolenaar <Bram@vim.org>
date Thu, 18 Jul 2019 14:00:08 +0200
parents 73e81cd9e6cb
children 967e2ee9b656
comparison
equal deleted inserted replaced
17428:30036b80e5ca 17429:6e756ad5ef1a
1919 " clean up 1919 " clean up
1920 call StopVimInTerminal(buf) 1920 call StopVimInTerminal(buf)
1921 call delete('XtestPopupMenuScroll') 1921 call delete('XtestPopupMenuScroll')
1922 endfunc 1922 endfunc
1923 1923
1924 func Test_popup_menu_filter()
1925 if !CanRunVimInTerminal()
1926 throw 'Skipped: cannot make screendumps'
1927 endif
1928
1929 let lines =<< trim END
1930 function! MyFilter(winid, key) abort
1931 if a:key == "0"
1932 call win_execute(a:winid, "call setpos('.', [0, 1, 1, 0])")
1933 return 1
1934 endif
1935 if a:key == "G"
1936 call win_execute(a:winid, "call setpos('.', [0, line('$'), 1, 0])")
1937 return 1
1938 endif
1939 if a:key == "j"
1940 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0])")
1941 return 1
1942 endif
1943 if a:key == "k"
1944 call win_execute(a:winid, "call setpos('.', [0, line('.') - 1, 1, 0])")
1945 return 1
1946 endif
1947 if a:key == 'x'
1948 call popup_close(a:winid)
1949 return 1
1950 endif
1951 return 0
1952 endfunction
1953 call popup_menu(['111', '222', '333', '444', '555', '666', '777', '888', '999'], #{
1954 \ maxheight : 3,
1955 \ filter : 'MyFilter'
1956 \ })
1957 END
1958 call writefile(lines, 'XtestPopupMenuFilter')
1959 let buf = RunVimInTerminal('-S XtestPopupMenuFilter', #{rows: 10})
1960
1961 call term_sendkeys(buf, "j")
1962 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_1', {})
1963
1964 call term_sendkeys(buf, "k")
1965 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_2', {})
1966
1967 call term_sendkeys(buf, "G")
1968 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_3', {})
1969
1970 call term_sendkeys(buf, "0")
1971 call VerifyScreenDump(buf, 'Test_popupwin_menu_filter_4', {})
1972
1973 call term_sendkeys(buf, "x")
1974
1975 " clean up
1976 call StopVimInTerminal(buf)
1977 call delete('XtestPopupMenuFilter')
1978 endfunc
1979
1980 func Test_popup_cursorline()
1981 if !CanRunVimInTerminal()
1982 throw 'Skipped: cannot make screendumps'
1983 endif
1984
1985 let winid = popup_create('some text', {})
1986 call assert_equal(0, popup_getoptions(winid).cursorline)
1987 call popup_close(winid)
1988
1989 let winid = popup_create('some text', #{ cursorline: 1, })
1990 call assert_equal(1, popup_getoptions(winid).cursorline)
1991 call popup_close(winid)
1992
1993 let winid = popup_create('some text', #{ cursorline: 0, })
1994 call assert_equal(0, popup_getoptions(winid).cursorline)
1995 call popup_close(winid)
1996
1997 let winid = popup_menu('some text', {})
1998 call assert_equal(1, popup_getoptions(winid).cursorline)
1999 call popup_close(winid)
2000
2001 let winid = popup_menu('some text', #{ cursorline: 1, })
2002 call assert_equal(1, popup_getoptions(winid).cursorline)
2003 call popup_close(winid)
2004
2005 let winid = popup_menu('some text', #{ cursorline: 0, })
2006 call assert_equal(0, popup_getoptions(winid).cursorline)
2007 call popup_close(winid)
2008
2009 " ---------
2010 " Pattern 1
2011 " ---------
2012 let lines =<< trim END
2013 call popup_create(['111', '222', '333'], #{ cursorline : 0 })
2014 END
2015 call writefile(lines, 'XtestPopupCursorLine')
2016 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2017 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_1', {})
2018 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2019 call StopVimInTerminal(buf)
2020
2021 " ---------
2022 " Pattern 2
2023 " ---------
2024 let lines =<< trim END
2025 call popup_create(['111', '222', '333'], #{ cursorline : 1 })
2026 END
2027 call writefile(lines, 'XtestPopupCursorLine')
2028 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2029 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_2', {})
2030 call term_sendkeys(buf, ":call popup_clear()\<cr>")
2031 call StopVimInTerminal(buf)
2032
2033 " ---------
2034 " Pattern 3
2035 " ---------
2036 let lines =<< trim END
2037 function! MyFilter(winid, key) abort
2038 if a:key == "j"
2039 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2040 return 1
2041 endif
2042 if a:key == 'x'
2043 call popup_close(a:winid)
2044 return 1
2045 endif
2046 return 0
2047 endfunction
2048 call popup_menu(['111', '222', '333'], #{
2049 \ cursorline : 0,
2050 \ maxheight : 2,
2051 \ filter : 'MyFilter',
2052 \ })
2053 END
2054 call writefile(lines, 'XtestPopupCursorLine')
2055 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2056 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_3', {})
2057 call term_sendkeys(buf, "j")
2058 call term_sendkeys(buf, "j")
2059 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_4', {})
2060 call term_sendkeys(buf, "x")
2061 call StopVimInTerminal(buf)
2062
2063 " ---------
2064 " Pattern 4
2065 " ---------
2066 let lines =<< trim END
2067 function! MyFilter(winid, key) abort
2068 if a:key == "j"
2069 call win_execute(a:winid, "call setpos('.', [0, line('.') + 1, 1, 0]) | redraw")
2070 return 1
2071 endif
2072 if a:key == 'x'
2073 call popup_close(a:winid)
2074 return 1
2075 endif
2076 return 0
2077 endfunction
2078 call popup_menu(['111', '222', '333'], #{
2079 \ cursorline : 1,
2080 \ maxheight : 2,
2081 \ filter : 'MyFilter',
2082 \ })
2083 END
2084 call writefile(lines, 'XtestPopupCursorLine')
2085 let buf = RunVimInTerminal('-S XtestPopupCursorLine', #{rows: 10})
2086 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_5', {})
2087 call term_sendkeys(buf, "j")
2088 call term_sendkeys(buf, "j")
2089 call VerifyScreenDump(buf, 'Test_popupwin_cursorline_6', {})
2090 call term_sendkeys(buf, "x")
2091 call StopVimInTerminal(buf)
2092
2093 call delete('XtestPopupCursorLine')
2094 endfunc
2095
1924 " vim: shiftwidth=2 sts=2 expandtab 2096 " vim: shiftwidth=2 sts=2 expandtab