blob: 50e2848800640e2368c1e14263802c2de4c780ab [file] [log] [blame]
Bram Moolenaar8e956362019-08-25 23:08:17 +02001" Tests for popup windows for text properties
2
3source check.vim
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004CheckFeature popupwin
Bram Moolenaar8e956362019-08-25 23:08:17 +02005CheckFeature textprop
6
7source screendump.vim
Bram Moolenaar8e956362019-08-25 23:08:17 +02008
9func Test_textprop_popup()
Drew Vogelea67ba72025-05-07 22:05:17 +020010 CheckScreendump
Bram Moolenaar8e956362019-08-25 23:08:17 +020011 let lines =<< trim END
12 call setline(1, range(1, 100))
13 call setline(50, 'some text to work with')
14 50
15 normal zz
16 set scrolloff=0
Bram Moolenaara37cb552019-11-16 20:03:31 +010017 call prop_type_add('popupMarker', #{highlight: 'DiffAdd', bufnr: bufnr('%')})
Bram Moolenaar8e956362019-08-25 23:08:17 +020018 call prop_add(50, 11, #{
19 \ length: 7,
20 \ type: 'popupMarker',
Bram Moolenaara37cb552019-11-16 20:03:31 +010021 \ bufnr: bufnr('%'),
Bram Moolenaar8e956362019-08-25 23:08:17 +020022 \ })
23 let winid = popup_create('the text', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +000024 \ pos: 'botleft',
Bram Moolenaar8e956362019-08-25 23:08:17 +020025 \ textprop: 'popupMarker',
26 \ border: [],
27 \ padding: [0,1,0,1],
28 \ close: 'click',
29 \ })
30 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +010031 call writefile(lines, 'XtestTextpropPopup', 'D')
Bram Moolenaar8e956362019-08-25 23:08:17 +020032 let buf = RunVimInTerminal('-S XtestTextpropPopup', #{rows: 10})
33 call VerifyScreenDump(buf, 'Test_popup_textprop_01', {})
34
35 call term_sendkeys(buf, "zt")
36 call VerifyScreenDump(buf, 'Test_popup_textprop_02', {})
37
38 call term_sendkeys(buf, "zzIawe\<Esc>")
39 call VerifyScreenDump(buf, 'Test_popup_textprop_03', {})
40
41 call term_sendkeys(buf, "0dw")
42 call VerifyScreenDump(buf, 'Test_popup_textprop_04', {})
43
44 call term_sendkeys(buf, "Oinserted\<Esc>")
45 call VerifyScreenDump(buf, 'Test_popup_textprop_05', {})
46
47 call term_sendkeys(buf, "k2dd")
48 call VerifyScreenDump(buf, 'Test_popup_textprop_06', {})
49
Bram Moolenaar1fb08312019-08-29 20:02:11 +020050 call term_sendkeys(buf, "4\<C-E>")
51 call VerifyScreenDump(buf, 'Test_popup_textprop_07', {})
52
Bram Moolenaar8e956362019-08-25 23:08:17 +020053 " clean up
54 call StopVimInTerminal(buf)
Bram Moolenaar8e956362019-08-25 23:08:17 +020055endfunc
56
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020057func Test_textprop_popup_corners()
Drew Vogelea67ba72025-05-07 22:05:17 +020058 CheckScreendump
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020059 let lines =<< trim END
60 call setline(1, range(1, 100))
61 call setline(50, 'now working with some longer text here')
62 50
63 normal zz
64 set scrolloff=0
65 call prop_type_add('popupMarker', #{highlight: 'DiffAdd'})
66 call prop_add(50, 23, #{
67 \ length: 6,
68 \ type: 'popupMarker',
69 \ })
70 let winid = popup_create('bottom left', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +000071 \ pos: 'botleft',
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020072 \ textprop: 'popupMarker',
Bram Moolenaara37cb552019-11-16 20:03:31 +010073 \ textpropwin: win_getid(),
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020074 \ padding: [0,1,0,1],
75 \ })
76 let winid = popup_create('bottom right', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +000077 \ pos: 'botright',
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020078 \ textprop: 'popupMarker',
79 \ border: [],
80 \ padding: [0,1,0,1],
81 \ })
82 let winid = popup_create('top left', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +000083 \ pos: 'topleft',
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020084 \ textprop: 'popupMarker',
85 \ border: [],
86 \ padding: [0,1,0,1],
87 \ })
88 let winid = popup_create('top right', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +000089 \ pos: 'topright',
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020090 \ textprop: 'popupMarker',
91 \ padding: [0,1,0,1],
92 \ })
93 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +010094 call writefile(lines, 'XtestTextpropPopupCorners', 'D')
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020095 let buf = RunVimInTerminal('-S XtestTextpropPopupCorners', #{rows: 12})
96 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_1', {})
97
98 call term_sendkeys(buf, "0dw")
99 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_2', {})
100
101 call term_sendkeys(buf, "46Goextra\<Esc>")
102 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_3', {})
103
104 call term_sendkeys(buf, "u")
Bram Moolenaar57441d62019-08-28 22:38:07 +0200105 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200106 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_4', {})
107
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200108 call term_sendkeys(buf, ":vsplit foo\<CR>")
109 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_5', {})
110
111 call term_sendkeys(buf, ":only!\<CR>")
112 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_6', {})
113
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200114 " clean up
115 call StopVimInTerminal(buf)
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200116endfunc
117
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200118func Test_textprop_popup_offsets()
Drew Vogelea67ba72025-05-07 22:05:17 +0200119 CheckScreendump
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200120 let lines =<< trim END
121 call setline(1, range(1, 100))
122 call setline(50, 'now working with some longer text here')
123 50
124 normal zz
125 set scrolloff=0
126 call prop_type_add('popupMarker', #{highlight: 'DiffAdd'})
127 call prop_add(50, 23, #{
128 \ length: 6,
129 \ type: 'popupMarker',
130 \ })
131 let winid = popup_create('bottom left', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +0000132 \ pos: 'botleft',
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200133 \ line: -1,
134 \ col: 2,
135 \ textprop: 'popupMarker',
136 \ padding: [0,1,0,1],
137 \ })
138 let winid = popup_create('bottom right', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +0000139 \ pos: 'botright',
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200140 \ line: -1,
141 \ col: -2,
142 \ textprop: 'popupMarker',
143 \ border: [],
144 \ padding: [0,1,0,1],
145 \ })
146 let winid = popup_create('top left', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +0000147 \ pos: 'topleft',
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200148 \ line: 1,
149 \ col: 2,
150 \ textprop: 'popupMarker',
151 \ border: [],
152 \ padding: [0,1,0,1],
153 \ })
154 let winid = popup_create('top right', #{
Bram Moolenaar94722c52023-01-28 19:19:03 +0000155 \ pos: 'topright',
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200156 \ line: 1,
157 \ col: -2,
158 \ textprop: 'popupMarker',
159 \ padding: [0,1,0,1],
160 \ })
161 END
Bram Moolenaar145d1fd2022-09-30 21:57:11 +0100162 call writefile(lines, 'XtestTextpropPopupOffset', 'D')
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200163 let buf = RunVimInTerminal('-S XtestTextpropPopupOffset', #{rows: 12})
164 call VerifyScreenDump(buf, 'Test_popup_textprop_off_1', {})
165
166 " test that removing the text property closes the popups
167 call term_sendkeys(buf, ":call prop_clear(50)\<CR>")
168 call VerifyScreenDump(buf, 'Test_popup_textprop_off_2', {})
169
170 " clean up
171 call StopVimInTerminal(buf)
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200172endfunc
173
Bram Moolenaar8e956362019-08-25 23:08:17 +0200174
175" vim: shiftwidth=2 sts=2