comparison src/popupwin.c @ 16817:069ee8dc8c8d v8.1.1410

patch 8.1.1410: popup_move() is not implemented yet commit https://github.com/vim/vim/commit/60cdb3004abe683e5e8851fa6c5d67b337df4443 Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 27 21:54:10 2019 +0200 patch 8.1.1410: popup_move() is not implemented yet Problem: Popup_move() is not implemented yet. Solution: Implement it. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/4441) Improve the positioning and resizing.
author Bram Moolenaar <Bram@vim.org>
date Mon, 27 May 2019 22:00:07 +0200
parents 4cfad94161f4
children 5cebaecad422
comparison
equal deleted inserted replaced
16816:b951a6ebd627 16817:069ee8dc8c8d
23 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict) 23 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict)
24 { 24 {
25 int nr; 25 int nr;
26 char_u *str; 26 char_u *str;
27 27
28 wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth");
29 wp->w_minheight = dict_get_number(dict, (char_u *)"minheight");
28 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth"); 30 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth");
29 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight"); 31 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight");
30 wp->w_winrow = dict_get_number(dict, (char_u *)"line"); 32
31 wp->w_wincol = dict_get_number(dict, (char_u *)"col"); 33 wp->w_wantline = dict_get_number(dict, (char_u *)"line");
34 wp->w_wantcol = dict_get_number(dict, (char_u *)"col");
35
32 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); 36 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex");
33 37
34 #if defined(FEAT_TIMERS) 38 #if defined(FEAT_TIMERS)
35 // Add timer to close the popup after some time. 39 // Add timer to close the popup after some time.
36 nr = dict_get_number(dict, (char_u *)"time"); 40 nr = dict_get_number(dict, (char_u *)"time");
143 } 147 }
144 } 148 }
145 } 149 }
146 150
147 /* 151 /*
152 * Adjust the position and size of the popup to fit on the screen.
153 */
154 static void
155 popup_adjust_position(win_T *wp)
156 {
157 // TODO: Compute the size and position properly.
158 if (wp->w_wantline > 0)
159 wp->w_winrow = wp->w_wantline - 1;
160 else
161 // TODO: better default
162 wp->w_winrow = Rows > 5 ? Rows / 2 - 2 : 0;
163 if (wp->w_winrow >= Rows)
164 wp->w_winrow = Rows - 1;
165
166 if (wp->w_wantcol > 0)
167 wp->w_wincol = wp->w_wantcol - 1;
168 else
169 // TODO: better default
170 wp->w_wincol = Columns > 20 ? Columns / 2 - 10 : 0;
171 if (wp->w_wincol >= Columns - 3)
172 wp->w_wincol = Columns - 3;
173
174 // TODO: set width based on longest text line and the 'wrap' option
175 wp->w_width = vim_strsize(ml_get_buf(wp->w_buffer, 1, FALSE));
176 if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth)
177 wp->w_width = wp->w_minwidth;
178 if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth)
179 wp->w_width = wp->w_maxwidth;
180 if (wp->w_width > Columns - wp->w_wincol)
181 wp->w_width = Columns - wp->w_wincol;
182
183 if (wp->w_height <= 1)
184 // TODO: adjust height for wrapped lines
185 wp->w_height = wp->w_buffer->b_ml.ml_line_count;
186 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight)
187 wp->w_height = wp->w_minheight;
188 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
189 wp->w_height = wp->w_maxheight;
190 if (wp->w_height > Rows - wp->w_winrow)
191 wp->w_height = Rows - wp->w_winrow;
192 }
193
194 /*
148 * popup_create({text}, {options}) 195 * popup_create({text}, {options})
149 */ 196 */
150 void 197 void
151 f_popup_create(typval_T *argvars, typval_T *rettv) 198 f_popup_create(typval_T *argvars, typval_T *rettv)
152 { 199 {
239 286
240 // set default values 287 // set default values
241 if (wp->w_zindex == 0) 288 if (wp->w_zindex == 0)
242 wp->w_zindex = 50; 289 wp->w_zindex = 50;
243 290
244 // TODO: Compute the size and position properly. 291 popup_adjust_position(wp);
245
246 // Default position is in middle of the screen, assuming a small popup
247 if (wp->w_winrow == 0)
248 wp->w_winrow = Rows > 5 ? Rows / 2 - 2 : 0;
249 else
250 --wp->w_winrow; // option value is one-based
251 if (wp->w_wincol == 0)
252 wp->w_wincol = Columns > 20 ? Columns / 2 - 10 : 0;
253 else
254 --wp->w_wincol; // option value is one-based
255
256
257 // TODO: set width based on longest text line and the 'wrap' option
258 wp->w_width = wp->w_maxwidth == 0 ? 20 : wp->w_maxwidth;
259 if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth)
260 wp->w_width = wp->w_maxwidth;
261 if (wp->w_width > Columns - wp->w_wincol)
262 wp->w_width = Columns - wp->w_wincol;
263
264 // TODO: adjust height for wrapped lines
265 wp->w_height = buf->b_ml.ml_line_count;
266 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
267 wp->w_height = wp->w_maxheight;
268 if (wp->w_height > Rows - wp->w_winrow)
269 wp->w_height = Rows - wp->w_winrow;
270 292
271 wp->w_vsep_width = 0; 293 wp->w_vsep_width = 0;
272 294
273 redraw_all_later(NOT_VALID); 295 redraw_all_later(NOT_VALID);
274 } 296 }
422 ex_popupclear(exarg_T *eap UNUSED) 444 ex_popupclear(exarg_T *eap UNUSED)
423 { 445 {
424 close_all_popups(); 446 close_all_popups();
425 } 447 }
426 448
449 /*
450 * popup_move({id}, {options})
451 */
452 void
453 f_popup_move(typval_T *argvars, typval_T *rettv UNUSED)
454 {
455 dict_T *d;
456 int nr;
457 int id = (int)tv_get_number(argvars);
458 win_T *wp = find_popup_win(id);
459
460 if (wp == NULL)
461 return; // invalid {id}
462
463 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
464 {
465 emsg(_(e_dictreq));
466 return;
467 }
468 d = argvars[1].vval.v_dict;
469
470 if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0)
471 wp->w_minwidth = nr;
472 if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0)
473 wp->w_minheight = nr;
474 if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0)
475 wp->w_maxwidth = nr;
476 if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0)
477 wp->w_maxheight = nr;
478 if ((nr = dict_get_number(d, (char_u *)"line")) > 0)
479 wp->w_wantline = nr;
480 if ((nr = dict_get_number(d, (char_u *)"col")) > 0)
481 wp->w_wantcol = nr;
482 // TODO: "pos"
483
484 if (wp->w_winrow + wp->w_height >= cmdline_row)
485 clear_cmdline = TRUE;
486 popup_adjust_position(wp);
487 redraw_all_later(NOT_VALID);
488 }
489
427 #endif // FEAT_TEXT_PROP 490 #endif // FEAT_TEXT_PROP