forked from aniani/vim
patch 8.1.1982: more functions can be used as methods
Problem: More functions can be used as methods. Solution: Make popup functions usable as a method.
This commit is contained in:
@@ -189,6 +189,9 @@ popup_atcursor({what}, {options}) *popup_atcursor()*
|
|||||||
\ })
|
\ })
|
||||||
< Use {options} to change the properties.
|
< Use {options} to change the properties.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetText()->popup_atcursor({})
|
||||||
|
|
||||||
|
|
||||||
popup_beval({what}, {options}) *popup_beval()*
|
popup_beval({what}, {options}) *popup_beval()*
|
||||||
Show the {what} above the position from 'ballooneval' and
|
Show the {what} above the position from 'ballooneval' and
|
||||||
@@ -203,7 +206,9 @@ popup_beval({what}, {options}) *popup_beval()*
|
|||||||
< Use {options} to change the properties.
|
< Use {options} to change the properties.
|
||||||
See |popup_beval_example| for an example use.
|
See |popup_beval_example| for an example use.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetText()->popup_beval({})
|
||||||
|
<
|
||||||
*popup_clear()*
|
*popup_clear()*
|
||||||
popup_clear() Emergency solution to a misbehaving plugin: close all popup
|
popup_clear() Emergency solution to a misbehaving plugin: close all popup
|
||||||
windows for the current tab and global popups.
|
windows for the current tab and global popups.
|
||||||
@@ -218,6 +223,8 @@ popup_close({id} [, {result}]) *popup_close()*
|
|||||||
it will be passed as the second argument of the callback.
|
it will be passed as the second argument of the callback.
|
||||||
Otherwise zero is passed to the callback.
|
Otherwise zero is passed to the callback.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetPopup()->popup_close()
|
||||||
|
|
||||||
popup_create({what}, {options}) *popup_create()*
|
popup_create({what}, {options}) *popup_create()*
|
||||||
Open a popup window showing {what}, which is either:
|
Open a popup window showing {what}, which is either:
|
||||||
@@ -240,6 +247,8 @@ popup_create({what}, {options}) *popup_create()*
|
|||||||
call setbufline(bufnr, 2, 'second line')
|
call setbufline(bufnr, 2, 'second line')
|
||||||
< In case of failure zero is returned.
|
< In case of failure zero is returned.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetText()->popup_create({})
|
||||||
|
|
||||||
popup_dialog({what}, {options}) *popup_dialog()*
|
popup_dialog({what}, {options}) *popup_dialog()*
|
||||||
Just like |popup_create()| but with these default options: >
|
Just like |popup_create()| but with these default options: >
|
||||||
@@ -261,6 +270,8 @@ popup_dialog({what}, {options}) *popup_dialog()*
|
|||||||
< By default the dialog can be dragged, so that text below it
|
< By default the dialog can be dragged, so that text below it
|
||||||
can be read if needed.
|
can be read if needed.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetText()->popup_dialog({})
|
||||||
|
|
||||||
popup_filter_menu({id}, {key}) *popup_filter_menu()*
|
popup_filter_menu({id}, {key}) *popup_filter_menu()*
|
||||||
Filter that can be used for a popup. These keys can be used:
|
Filter that can be used for a popup. These keys can be used:
|
||||||
@@ -337,6 +348,8 @@ popup_getoptions({id}) *popup_getoptions()*
|
|||||||
|
|
||||||
If popup window {id} is not found an empty Dict is returned.
|
If popup window {id} is not found an empty Dict is returned.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetPopup()->popup_getoptions()
|
||||||
|
|
||||||
popup_getpos({id}) *popup_getpos()*
|
popup_getpos({id}) *popup_getpos()*
|
||||||
Return the position and size of popup {id}. Returns a Dict
|
Return the position and size of popup {id}. Returns a Dict
|
||||||
@@ -361,6 +374,8 @@ popup_getpos({id}) *popup_getpos()*
|
|||||||
|
|
||||||
If popup window {id} is not found an empty Dict is returned.
|
If popup window {id} is not found an empty Dict is returned.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetPopup()->popup_getpos()
|
||||||
|
|
||||||
popup_hide({id}) *popup_hide()*
|
popup_hide({id}) *popup_hide()*
|
||||||
If {id} is a displayed popup, hide it now. If the popup has a
|
If {id} is a displayed popup, hide it now. If the popup has a
|
||||||
@@ -369,6 +384,8 @@ popup_hide({id}) *popup_hide()*
|
|||||||
If window {id} does not exist nothing happens. If window {id}
|
If window {id} does not exist nothing happens. If window {id}
|
||||||
exists but is not a popup window an error is given. *E993*
|
exists but is not a popup window an error is given. *E993*
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetPopup()->popup_hide()
|
||||||
|
|
||||||
popup_locate({row}, {col}) *popup_locate()*
|
popup_locate({row}, {col}) *popup_locate()*
|
||||||
Return the |window-ID| of the popup at screen position {row}
|
Return the |window-ID| of the popup at screen position {row}
|
||||||
@@ -406,6 +423,8 @@ popup_menu({what}, {options}) *popup_menu()*
|
|||||||
\ callback: 'ColorSelected',
|
\ callback: 'ColorSelected',
|
||||||
\ })
|
\ })
|
||||||
|
|
||||||
|
< Can also be used as a |method|: >
|
||||||
|
GetChoices()->popup_menu({})
|
||||||
|
|
||||||
popup_move({id}, {options}) *popup_move()*
|
popup_move({id}, {options}) *popup_move()*
|
||||||
Move popup {id} to the position specified with {options}.
|
Move popup {id} to the position specified with {options}.
|
||||||
@@ -422,6 +441,8 @@ popup_move({id}, {options}) *popup_move()*
|
|||||||
For {id} see `popup_hide()`.
|
For {id} see `popup_hide()`.
|
||||||
For other options see |popup_setoptions()|.
|
For other options see |popup_setoptions()|.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetPopup()->popup_move(options)
|
||||||
|
|
||||||
popup_notification({what}, {options}) *popup_notification()*
|
popup_notification({what}, {options}) *popup_notification()*
|
||||||
Show the {what} for 3 seconds at the top of the Vim window.
|
Show the {what} for 3 seconds at the top of the Vim window.
|
||||||
@@ -449,6 +470,8 @@ popup_notification({what}, {options}) *popup_notification()*
|
|||||||
notifications.
|
notifications.
|
||||||
Use {options} to change the properties.
|
Use {options} to change the properties.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetText()->popup_notification({})
|
||||||
|
|
||||||
popup_show({id}) *popup_show()*
|
popup_show({id}) *popup_show()*
|
||||||
If {id} is a hidden popup, show it now.
|
If {id} is a hidden popup, show it now.
|
||||||
@@ -485,6 +508,9 @@ popup_setoptions({id}, {options}) *popup_setoptions()*
|
|||||||
For "hidden" use |popup_hide()| and |popup_show()|.
|
For "hidden" use |popup_hide()| and |popup_show()|.
|
||||||
"tabpage" cannot be changed.
|
"tabpage" cannot be changed.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetPopup()->popup_setoptions(options)
|
||||||
|
|
||||||
popup_settext({id}, {text}) *popup_settext()*
|
popup_settext({id}, {text}) *popup_settext()*
|
||||||
Set the text of the buffer in popup win {id}. {text} is the
|
Set the text of the buffer in popup win {id}. {text} is the
|
||||||
same as supplied to |popup_create()|, except that a buffer
|
same as supplied to |popup_create()|, except that a buffer
|
||||||
@@ -492,6 +518,8 @@ popup_settext({id}, {text}) *popup_settext()*
|
|||||||
Does not change the window size or position, other than caused
|
Does not change the window size or position, other than caused
|
||||||
by the different text.
|
by the different text.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetPopup()->popup_settext('hello')
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
3. Usage *popup-usage*
|
3. Usage *popup-usage*
|
||||||
|
@@ -633,26 +633,26 @@ static funcentry_T global_functions[] =
|
|||||||
{"perleval", 1, 1, 0, f_perleval},
|
{"perleval", 1, 1, 0, f_perleval},
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_TEXT_PROP
|
#ifdef FEAT_TEXT_PROP
|
||||||
{"popup_atcursor", 2, 2, 0, f_popup_atcursor},
|
{"popup_atcursor", 2, 2, FEARG_1, f_popup_atcursor},
|
||||||
{"popup_beval", 2, 2, 0, f_popup_beval},
|
{"popup_beval", 2, 2, FEARG_1, f_popup_beval},
|
||||||
{"popup_clear", 0, 0, 0, f_popup_clear},
|
{"popup_clear", 0, 0, 0, f_popup_clear},
|
||||||
{"popup_close", 1, 2, 0, f_popup_close},
|
{"popup_close", 1, 2, FEARG_1, f_popup_close},
|
||||||
{"popup_create", 2, 2, 0, f_popup_create},
|
{"popup_create", 2, 2, FEARG_1, f_popup_create},
|
||||||
{"popup_dialog", 2, 2, 0, f_popup_dialog},
|
{"popup_dialog", 2, 2, FEARG_1, f_popup_dialog},
|
||||||
{"popup_filter_menu", 2, 2, 0, f_popup_filter_menu},
|
{"popup_filter_menu", 2, 2, 0, f_popup_filter_menu},
|
||||||
{"popup_filter_yesno", 2, 2, 0, f_popup_filter_yesno},
|
{"popup_filter_yesno", 2, 2, 0, f_popup_filter_yesno},
|
||||||
{"popup_findinfo", 0, 0, 0, f_popup_findinfo},
|
{"popup_findinfo", 0, 0, 0, f_popup_findinfo},
|
||||||
{"popup_findpreview", 0, 0, 0, f_popup_findpreview},
|
{"popup_findpreview", 0, 0, 0, f_popup_findpreview},
|
||||||
{"popup_getoptions", 1, 1, 0, f_popup_getoptions},
|
{"popup_getoptions", 1, 1, FEARG_1, f_popup_getoptions},
|
||||||
{"popup_getpos", 1, 1, 0, f_popup_getpos},
|
{"popup_getpos", 1, 1, FEARG_1, f_popup_getpos},
|
||||||
{"popup_hide", 1, 1, 0, f_popup_hide},
|
{"popup_hide", 1, 1, FEARG_1, f_popup_hide},
|
||||||
{"popup_locate", 2, 2, 0, f_popup_locate},
|
{"popup_locate", 2, 2, 0, f_popup_locate},
|
||||||
{"popup_menu", 2, 2, 0, f_popup_menu},
|
{"popup_menu", 2, 2, FEARG_1, f_popup_menu},
|
||||||
{"popup_move", 2, 2, 0, f_popup_move},
|
{"popup_move", 2, 2, FEARG_1, f_popup_move},
|
||||||
{"popup_notification", 2, 2, 0, f_popup_notification},
|
{"popup_notification", 2, 2, FEARG_1, f_popup_notification},
|
||||||
{"popup_setoptions", 2, 2, 0, f_popup_setoptions},
|
{"popup_setoptions", 2, 2, FEARG_1, f_popup_setoptions},
|
||||||
{"popup_settext", 2, 2, 0, f_popup_settext},
|
{"popup_settext", 2, 2, FEARG_1, f_popup_settext},
|
||||||
{"popup_show", 1, 1, 0, f_popup_show},
|
{"popup_show", 1, 1, FEARG_1, f_popup_show},
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_FLOAT
|
#ifdef FEAT_FLOAT
|
||||||
{"pow", 2, 2, FEARG_1, f_pow},
|
{"pow", 2, 2, FEARG_1, f_pow},
|
||||||
|
@@ -145,7 +145,7 @@ func Test_popup_with_border_and_padding()
|
|||||||
\ scrollbar: 0,
|
\ scrollbar: 0,
|
||||||
\ visible: 1}
|
\ visible: 1}
|
||||||
let winid = popup_create('hello border', #{line: 2, col: 3, border: []})",
|
let winid = popup_create('hello border', #{line: 2, col: 3, border: []})",
|
||||||
call assert_equal(with_border_or_padding, popup_getpos(winid))
|
call assert_equal(with_border_or_padding, winid->popup_getpos())
|
||||||
let options = popup_getoptions(winid)
|
let options = popup_getoptions(winid)
|
||||||
call assert_equal([], options.border)
|
call assert_equal([], options.border)
|
||||||
call assert_false(has_key(options, "padding"))
|
call assert_false(has_key(options, "padding"))
|
||||||
@@ -337,7 +337,7 @@ func Test_popup_firstline()
|
|||||||
call assert_equal(3, popup_getoptions(winid).firstline)
|
call assert_equal(3, popup_getoptions(winid).firstline)
|
||||||
call popup_setoptions(winid, #{firstline: 1})
|
call popup_setoptions(winid, #{firstline: 1})
|
||||||
call assert_equal(1, popup_getoptions(winid).firstline)
|
call assert_equal(1, popup_getoptions(winid).firstline)
|
||||||
call popup_close(winid)
|
eval winid->popup_close()
|
||||||
|
|
||||||
let winid = popup_create(['xxx']->repeat(50), #{
|
let winid = popup_create(['xxx']->repeat(50), #{
|
||||||
\ maxheight: 3,
|
\ maxheight: 3,
|
||||||
@@ -878,7 +878,7 @@ func Test_popup_hide()
|
|||||||
" buffer is still listed but hidden
|
" buffer is still listed but hidden
|
||||||
call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
|
call assert_match(winbufnr(winid) .. 'u h.*\[Popup\]', execute('ls u'))
|
||||||
|
|
||||||
call popup_show(winid)
|
eval winid->popup_show()
|
||||||
redraw
|
redraw
|
||||||
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
|
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
|
||||||
call assert_equal('world', line)
|
call assert_equal('world', line)
|
||||||
@@ -894,7 +894,7 @@ func Test_popup_hide()
|
|||||||
call assert_fails('call popup_hide(win_getid())', 'E993:')
|
call assert_fails('call popup_hide(win_getid())', 'E993:')
|
||||||
|
|
||||||
" no error non-existing window
|
" no error non-existing window
|
||||||
call popup_hide(1234234)
|
eval 1234234->popup_hide()
|
||||||
call popup_show(41234234)
|
call popup_show(41234234)
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
@@ -920,7 +920,7 @@ func Test_popup_move()
|
|||||||
let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
|
let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
|
||||||
call assert_equal('~world', line)
|
call assert_equal('~world', line)
|
||||||
|
|
||||||
call popup_move(winid, #{line: 1})
|
eval winid->popup_move(#{line: 1})
|
||||||
redraw
|
redraw
|
||||||
let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
|
let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
|
||||||
call assert_equal('hworld', line)
|
call assert_equal('hworld', line)
|
||||||
@@ -1076,7 +1076,7 @@ func Test_popup_atcursor()
|
|||||||
|
|
||||||
call cursor(3, 4)
|
call cursor(3, 4)
|
||||||
redraw
|
redraw
|
||||||
let winid = popup_atcursor('vim', {})
|
let winid = 'vim'->popup_atcursor({})
|
||||||
redraw
|
redraw
|
||||||
let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
|
let line = join(map(range(1, 17), 'screenstring(2, v:val)'), '')
|
||||||
call assert_equal('xxxvimxxxxxxxxxxx', line)
|
call assert_equal('xxxvimxxxxxxxxxxx', line)
|
||||||
@@ -1144,7 +1144,7 @@ func Test_popup_beval()
|
|||||||
set balloonexpr=BalloonExpr()
|
set balloonexpr=BalloonExpr()
|
||||||
set balloondelay=100
|
set balloondelay=100
|
||||||
func BalloonExpr()
|
func BalloonExpr()
|
||||||
let s:winid = popup_beval([v:beval_text], {})
|
let s:winid = [v:beval_text]->popup_beval({})
|
||||||
return ''
|
return ''
|
||||||
endfunc
|
endfunc
|
||||||
func Hover()
|
func Hover()
|
||||||
@@ -1199,7 +1199,7 @@ func Test_popup_filter()
|
|||||||
return 0
|
return 0
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
let winid = popup_create('something', #{filter: 'MyPopupFilter'})
|
let winid = 'something'->popup_create(#{filter: 'MyPopupFilter'})
|
||||||
redraw
|
redraw
|
||||||
|
|
||||||
" e is consumed by the filter
|
" e is consumed by the filter
|
||||||
@@ -1787,7 +1787,7 @@ func Test_popup_settext()
|
|||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
let opts = #{wrap: 0}
|
let opts = #{wrap: 0}
|
||||||
let p = popup_create('test', opts)
|
let p = popup_create('test', opts)
|
||||||
call popup_settext(p, 'this is a text')
|
eval p->popup_settext('this is a text')
|
||||||
END
|
END
|
||||||
|
|
||||||
call writefile(lines, 'XtestPopupSetText')
|
call writefile(lines, 'XtestPopupSetText')
|
||||||
@@ -1840,7 +1840,7 @@ func Test_popup_hidden()
|
|||||||
let s:cb_winid = a:id
|
let s:cb_winid = a:id
|
||||||
let s:cb_res = a:res
|
let s:cb_res = a:res
|
||||||
endfunc
|
endfunc
|
||||||
let winid = popup_dialog('make a choice', #{hidden: 1,
|
let winid = 'make a choice'->popup_dialog(#{hidden: 1,
|
||||||
\ filter: 'popup_filter_yesno',
|
\ filter: 'popup_filter_yesno',
|
||||||
\ callback: 'QuitCallback',
|
\ callback: 'QuitCallback',
|
||||||
\ })
|
\ })
|
||||||
@@ -2020,7 +2020,7 @@ func Test_popupwin_width()
|
|||||||
\ maxheight: 10,
|
\ maxheight: 10,
|
||||||
\ })
|
\ })
|
||||||
for top in range(1, 20)
|
for top in range(1, 20)
|
||||||
call popup_setoptions(winid, #{firstline: top})
|
eval winid->popup_setoptions(#{firstline: top})
|
||||||
redraw
|
redraw
|
||||||
call assert_equal(19, popup_getpos(winid).width)
|
call assert_equal(19, popup_getpos(winid).width)
|
||||||
endfor
|
endfor
|
||||||
@@ -2100,8 +2100,9 @@ func Test_popup_menu_with_scrollbar()
|
|||||||
call setline(1, range(1, 20))
|
call setline(1, range(1, 20))
|
||||||
hi ScrollThumb ctermbg=blue
|
hi ScrollThumb ctermbg=blue
|
||||||
hi ScrollBar ctermbg=red
|
hi ScrollBar ctermbg=red
|
||||||
call popup_menu(['one', 'two', 'three', 'four', 'five',
|
eval ['one', 'two', 'three', 'four', 'five',
|
||||||
\ 'six', 'seven', 'eight', 'nine'], #{
|
\ 'six', 'seven', 'eight', 'nine']
|
||||||
|
\ ->popup_menu(#{
|
||||||
\ minwidth: 8,
|
\ minwidth: 8,
|
||||||
\ maxheight: 3,
|
\ maxheight: 3,
|
||||||
\ })
|
\ })
|
||||||
@@ -2435,7 +2436,7 @@ func Get_popupmenu_lines()
|
|||||||
call setline(1, 'text text text text text text text ')
|
call setline(1, 'text text text text text text text ')
|
||||||
func ChangeColor()
|
func ChangeColor()
|
||||||
let id = popup_findinfo()
|
let id = popup_findinfo()
|
||||||
call popup_setoptions(id, #{highlight: 'InfoPopup'})
|
eval id->popup_setoptions(#{highlight: 'InfoPopup'})
|
||||||
endfunc
|
endfunc
|
||||||
END
|
END
|
||||||
return lines
|
return lines
|
||||||
@@ -2522,7 +2523,7 @@ endfunc
|
|||||||
func Test_popupwin_recycle_bnr()
|
func Test_popupwin_recycle_bnr()
|
||||||
let bufnr = popup_notification('nothing wrong', {})->winbufnr()
|
let bufnr = popup_notification('nothing wrong', {})->winbufnr()
|
||||||
call popup_clear()
|
call popup_clear()
|
||||||
let winid = popup_notification('nothing wrong', {})
|
let winid = 'nothing wrong'->popup_notification({})
|
||||||
call assert_equal(bufnr, winbufnr(winid))
|
call assert_equal(bufnr, winbufnr(winid))
|
||||||
call popup_clear()
|
call popup_clear()
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -757,6 +757,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1982,
|
||||||
/**/
|
/**/
|
||||||
1981,
|
1981,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user