Skip to content

Commit 5ad315f

Browse files
committed
popup.txt: Update Vim 8.2.5167
1 parent 0a6e432 commit 5ad315f

File tree

1 file changed

+62
-66
lines changed

1 file changed

+62
-66
lines changed

en/popup.txt

Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*popup.txt* For Vim version 8.2. Last change: 2022 Jun 06
1+
*popup.txt* For Vim version 8.2. Last change: 2022 Jun 16
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1001,8 +1001,6 @@ To make the four corners transparent:
10011001

10021002
These examples use |Vim9| script.
10031003

1004-
TODO: more interesting examples
1005-
10061004
*popup_dialog-example*
10071005
Prompt the user to press y/Y or n/N: >
10081006
@@ -1015,89 +1013,87 @@ Prompt the user to press y/Y or n/N: >
10151013
echomsg "'y' or 'Y' was NOT pressed"
10161014
endif
10171015
},
1016+
padding: [2, 4, 2, 4],
10181017
})
10191018
<
10201019
*popup_menu-shortcut-example*
10211020
Extend popup_filter_menu() with shortcut keys: >
10221021
1023-
call popup_menu(['Save', 'Cancel', 'Discard'], #{
1024-
\ filter: 'MyMenuFilter',
1025-
\ callback: 'MyMenuHandler',
1026-
\ })
1027-
1028-
func MyMenuFilter(id, key)
1029-
" Handle shortcuts
1030-
if a:key == 'S'
1031-
call popup_close(a:id, 1)
1032-
return 1
1033-
endif
1034-
if a:key == 'C'
1035-
call popup_close(a:id, 2)
1036-
return 1
1037-
endif
1038-
if a:key == 'D'
1039-
call popup_close(a:id, 3)
1040-
return 1
1041-
endif
1042-
1043-
" No shortcut, pass to generic filter
1044-
return popup_filter_menu(a:id, a:key)
1045-
endfunc
1046-
1047-
func MyMenuHandler(id, result)
1048-
echo $'Result: {a:result}'
1049-
endfunc
1022+
popup_menu(['Save', 'Cancel', 'Discard'], {
1023+
callback: (_, result) => {
1024+
echo 'dialog result is' result
1025+
},
1026+
filter: (id, key) => {
1027+
# Handle shortcuts
1028+
if key == 'S' || key == 's'
1029+
popup_close(id, 1)
1030+
elseif key == 'C' || key == 'c'
1031+
popup_close(id, 2)
1032+
elseif key == 'D' || key == 'd'
1033+
popup_close(id, 3)
1034+
else
1035+
# No shortcut, pass to generic filter
1036+
return popup_filter_menu(id, key)
1037+
endif
1038+
return true
1039+
},
1040+
})
10501041
<
10511042
*popup_beval_example*
10521043
Example for using a popup window for 'ballooneval': >
10531044
10541045
set ballooneval balloonevalterm
10551046
set balloonexpr=BalloonExpr()
1056-
let s:winid = 0
1057-
let s:last_text = ''
1058-
1059-
func BalloonExpr()
1060-
if s:winid && popup_getpos(s:winid) != {}
1061-
" previous popup window still shows
1062-
if v:beval_text == s:last_text
1063-
" Still the same text, keep the existing popup
1064-
return ''
1047+
var winid: number
1048+
var last_text: string
1049+
1050+
def BalloonExpr(): string
1051+
# here you would use "v:beval_text" to lookup something interesting
1052+
var text = v:beval_text
1053+
if winid > 0 && popup_getpos(winid) != null_dict
1054+
# previous popup window still shows
1055+
if text == last_text
1056+
# still the same text, keep the existing popup
1057+
return null_string
1058+
endif
1059+
popup_close(winid)
10651060
endif
1066-
call popup_close(s:winid)
1067-
endif
1068-
let s:winid = popup_beval(v:beval_text, #{mousemoved: 'word'})
1069-
let s:last_text = v:beval_text
1070-
return ''
1071-
endfunc
1072-
<
1061+
1062+
winid = popup_beval(text, {})
1063+
last_text = text
1064+
return null_string
1065+
enddef
1066+
10731067
If the text has to be obtained asynchronously return an empty string from the
10741068
expression function and call popup_beval() once the text is available. In
10751069
this example simulated with a timer callback: >
10761070
10771071
set ballooneval balloonevalterm
10781072
set balloonexpr=BalloonExpr()
1079-
let s:winid = 0
1080-
let s:balloonText = ''
1081-
1082-
func BalloonExpr()
1083-
if s:winid && popup_getpos(s:winid) != {}
1084-
" previous popup window still shows
1085-
if v:beval_text == s:balloonText
1086-
" Still the same text, keep the existing popup
1087-
return ''
1073+
var winid: number
1074+
var last_text: string
1075+
1076+
def BalloonExpr(): string
1077+
var text = v:beval_text
1078+
if winid > 0 && popup_getpos(winid) != null_dict
1079+
# previous popup window still shows
1080+
if text == last_text
1081+
# still the same text, keep the existing popup
1082+
return null_string
1083+
endif
1084+
popup_close(winid)
10881085
endif
1089-
call popup_close(s:winid)
1090-
let s:winid = 0
1091-
endif
1092-
" simulate an asynchronous lookup for the text to display
1093-
let s:balloonText = v:beval_text
1094-
call timer_start(100, 'ShowPopup')
1095-
return ''
1096-
endfunc
10971086
1098-
func ShowPopup(id)
1099-
let s:winid = popup_beval(s:balloonText, #{mousemoved: 'word'})
1100-
endfunc
1087+
# Simulate an asynchronous lookup that takes half a second for the
1088+
# text to display.
1089+
last_text = text
1090+
timer_start(500, 'ShowPopup')
1091+
return null_string
1092+
enddef
1093+
1094+
def ShowPopup(timerid: number)
1095+
winid = popup_beval('Result: ' .. last_text, {})
1096+
enddef
11011097
<
11021098

11031099
vim:tw=78:ts=8:noet:ft=help:norl:

0 commit comments

Comments
 (0)