Mercurial > vim
comparison src/popupwin.c @ 16853:e6bcccccbf7b v8.1.1428
patch 8.1.1428: popup_atcursor() not implemented yet
commit https://github.com/vim/vim/commit/cc31ad9f9b601d53926b96586bd6b40602d57951
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 30 19:25:06 2019 +0200
patch 8.1.1428: popup_atcursor() not implemented yet
Problem: Popup_atcursor() not implemented yet.
Solution: Implement it. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/4456)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 30 May 2019 19:30:03 +0200 |
parents | 48c06fcb8be7 |
children | 19162ff4eacd |
comparison
equal
deleted
inserted
replaced
16852:014021a1f556 | 16853:e6bcccccbf7b |
---|---|
14 #include "vim.h" | 14 #include "vim.h" |
15 | 15 |
16 #ifdef FEAT_TEXT_PROP | 16 #ifdef FEAT_TEXT_PROP |
17 | 17 |
18 /* | 18 /* |
19 * Get option value for"key", which is "line" or "col". | |
20 * Handles "cursor+N" and "cursor-N". | |
21 */ | |
22 static int | |
23 popup_options_pos(dict_T *dict, char_u *key) | |
24 { | |
25 dictitem_T *di; | |
26 char_u *val; | |
27 char_u *s; | |
28 char_u *endp; | |
29 int n = 0; | |
30 | |
31 di = dict_find(dict, key, -1); | |
32 if (di == NULL) | |
33 return 0; | |
34 | |
35 val = tv_get_string(&di->di_tv); | |
36 if (STRNCMP(val, "cursor", 6) != 0) | |
37 return dict_get_number(dict, key); | |
38 | |
39 setcursor_mayforce(TRUE); | |
40 s = val + 6; | |
41 if (*s != NUL) | |
42 { | |
43 n = strtol((char *)s, (char **)&endp, 10); | |
44 if (endp != NULL && *skipwhite(endp) != NUL) | |
45 { | |
46 semsg(_(e_invexpr2), val); | |
47 return 0; | |
48 } | |
49 } | |
50 | |
51 if (STRCMP(key, "line") == 0) | |
52 n = screen_screenrow() + 1 + n; | |
53 else // "col" | |
54 n = screen_screencol() + 1 + n; | |
55 | |
56 if (n < 1) | |
57 n = 1; | |
58 return n; | |
59 } | |
60 | |
61 /* | |
19 * Go through the options in "dict" and apply them to buffer "buf" displayed in | 62 * Go through the options in "dict" and apply them to buffer "buf" displayed in |
20 * popup window "wp". | 63 * popup window "wp". |
64 * When called from f_popup_atcursor() "atcursor" is TRUE. | |
21 */ | 65 */ |
22 static void | 66 static void |
23 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict) | 67 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor) |
24 { | 68 { |
25 int nr; | 69 int nr; |
26 char_u *str; | 70 char_u *str; |
27 | 71 |
28 wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth"); | 72 wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth"); |
29 wp->w_minheight = dict_get_number(dict, (char_u *)"minheight"); | 73 wp->w_minheight = dict_get_number(dict, (char_u *)"minheight"); |
30 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth"); | 74 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth"); |
31 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight"); | 75 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight"); |
32 | 76 |
33 wp->w_wantline = dict_get_number(dict, (char_u *)"line"); | 77 if (atcursor) |
34 wp->w_wantcol = dict_get_number(dict, (char_u *)"col"); | 78 { |
79 setcursor_mayforce(TRUE); | |
80 wp->w_wantline = screen_screenrow(); | |
81 wp->w_wantcol = screen_screencol() + 1; | |
82 } | |
83 | |
84 nr = popup_options_pos(dict, (char_u *)"line"); | |
85 if (nr > 0) | |
86 wp->w_wantline = nr; | |
87 nr = popup_options_pos(dict, (char_u *)"col"); | |
88 if (nr > 0) | |
89 wp->w_wantcol = nr; | |
35 | 90 |
36 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); | 91 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); |
37 | 92 |
38 #if defined(FEAT_TIMERS) | 93 #if defined(FEAT_TIMERS) |
39 // Add timer to close the popup after some time. | 94 // Add timer to close the popup after some time. |
213 wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); | 268 wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); |
214 } | 269 } |
215 | 270 |
216 /* | 271 /* |
217 * popup_create({text}, {options}) | 272 * popup_create({text}, {options}) |
218 */ | 273 * popup_atcursor({text}, {options}) |
219 void | 274 * When called from f_popup_atcursor() "atcursor" is TRUE. |
220 f_popup_create(typval_T *argvars, typval_T *rettv) | 275 */ |
276 static void | |
277 popup_create(typval_T *argvars, typval_T *rettv, int atcursor) | |
221 { | 278 { |
222 win_T *wp; | 279 win_T *wp; |
223 buf_T *buf; | 280 buf_T *buf; |
224 dict_T *d; | 281 dict_T *d; |
225 int nr; | 282 int nr; |
307 curbuf = buf; | 364 curbuf = buf; |
308 ml_delete(buf->b_ml.ml_line_count, FALSE); | 365 ml_delete(buf->b_ml.ml_line_count, FALSE); |
309 curbuf = curwin->w_buffer; | 366 curbuf = curwin->w_buffer; |
310 | 367 |
311 // Deal with options. | 368 // Deal with options. |
312 apply_options(wp, buf, argvars[1].vval.v_dict); | 369 apply_options(wp, buf, argvars[1].vval.v_dict, atcursor); |
313 | 370 |
314 // set default values | 371 // set default values |
315 if (wp->w_zindex == 0) | 372 if (wp->w_zindex == 0) |
316 wp->w_zindex = 50; | 373 wp->w_zindex = 50; |
317 | 374 |
318 popup_adjust_position(wp); | 375 popup_adjust_position(wp); |
319 | 376 |
320 wp->w_vsep_width = 0; | 377 wp->w_vsep_width = 0; |
321 | 378 |
322 redraw_all_later(NOT_VALID); | 379 redraw_all_later(NOT_VALID); |
380 } | |
381 | |
382 /* | |
383 * popup_create({text}, {options}) | |
384 */ | |
385 void | |
386 f_popup_create(typval_T *argvars, typval_T *rettv) | |
387 { | |
388 popup_create(argvars, rettv, FALSE); | |
389 } | |
390 | |
391 /* | |
392 * popup_atcursor({text}, {options}) | |
393 */ | |
394 void | |
395 f_popup_atcursor(typval_T *argvars, typval_T *rettv) | |
396 { | |
397 popup_create(argvars, rettv, TRUE); | |
323 } | 398 } |
324 | 399 |
325 /* | 400 /* |
326 * Find the popup window with window-ID "id". | 401 * Find the popup window with window-ID "id". |
327 * If the popup window does not exist NULL is returned. | 402 * If the popup window does not exist NULL is returned. |