Mercurial > vim
comparison src/popupwin.c @ 17879:5d5b460926ca v8.1.1936
patch 8.1.1936: not enough tests for text property popup window
Commit: https://github.com/vim/vim/commit/1fb0831a0e9f9b6f18f1f8b549191bd547d0e095
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 29 20:02:11 2019 +0200
patch 8.1.1936: not enough tests for text property popup window
Problem: Not enough tests for text property popup window.
Solution: Add a few more tests. Make negative offset work. Close all
popups when window closes.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 29 Aug 2019 20:15:04 +0200 |
parents | f13a5c48320b |
children | fa032e079825 |
comparison
equal
deleted
inserted
replaced
17878:74fec19ccefb | 17879:5d5b460926ca |
---|---|
31 static void popup_adjust_position(win_T *wp); | 31 static void popup_adjust_position(win_T *wp); |
32 | 32 |
33 /* | 33 /* |
34 * Get option value for "key", which is "line" or "col". | 34 * Get option value for "key", which is "line" or "col". |
35 * Handles "cursor+N" and "cursor-N". | 35 * Handles "cursor+N" and "cursor-N". |
36 * Returns MAXCOL if the entry is not present. | |
36 */ | 37 */ |
37 static int | 38 static int |
38 popup_options_one(dict_T *dict, char_u *key) | 39 popup_options_one(dict_T *dict, char_u *key) |
39 { | 40 { |
40 dictitem_T *di; | 41 dictitem_T *di; |
43 char_u *endp; | 44 char_u *endp; |
44 int n = 0; | 45 int n = 0; |
45 | 46 |
46 di = dict_find(dict, key, -1); | 47 di = dict_find(dict, key, -1); |
47 if (di == NULL) | 48 if (di == NULL) |
48 return 0; | 49 return MAXCOL; |
49 | 50 |
50 val = tv_get_string(&di->di_tv); | 51 val = tv_get_string(&di->di_tv); |
51 if (STRNCMP(val, "cursor", 6) != 0) | 52 if (STRNCMP(val, "cursor", 6) != 0) |
52 return dict_get_number_check(dict, key); | 53 return dict_get_number_check(dict, key); |
53 | 54 |
406 wp->w_maxwidth = nr; | 407 wp->w_maxwidth = nr; |
407 if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) | 408 if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) |
408 wp->w_maxheight = nr; | 409 wp->w_maxheight = nr; |
409 | 410 |
410 nr = popup_options_one(d, (char_u *)"line"); | 411 nr = popup_options_one(d, (char_u *)"line"); |
411 if (nr > 0) | 412 if (nr != MAXCOL) |
412 wp->w_wantline = nr; | 413 wp->w_wantline = nr; |
413 nr = popup_options_one(d, (char_u *)"col"); | 414 nr = popup_options_one(d, (char_u *)"col"); |
414 if (nr > 0) | 415 if (nr != MAXCOL) |
415 wp->w_wantcol = nr; | 416 wp->w_wantcol = nr; |
416 | 417 |
417 di = dict_find(d, (char_u *)"fixed", -1); | 418 di = dict_find(d, (char_u *)"fixed", -1); |
418 if (di != NULL) | 419 if (di != NULL) |
419 wp->w_popup_fixed = dict_get_number(d, (char_u *)"fixed") != 0; | 420 wp->w_popup_fixed = dict_get_number(d, (char_u *)"fixed") != 0; |
1112 center_vert = TRUE; | 1113 center_vert = TRUE; |
1113 center_hor = TRUE; | 1114 center_hor = TRUE; |
1114 } | 1115 } |
1115 else | 1116 else |
1116 { | 1117 { |
1117 if (wantline != 0 && (wp->w_popup_pos == POPPOS_TOPLEFT | 1118 if (wantline > 0 && (wp->w_popup_pos == POPPOS_TOPLEFT |
1118 || wp->w_popup_pos == POPPOS_TOPRIGHT)) | 1119 || wp->w_popup_pos == POPPOS_TOPRIGHT)) |
1119 { | 1120 { |
1120 wp->w_winrow = wantline - 1; | 1121 wp->w_winrow = wantline - 1; |
1121 if (wp->w_winrow >= Rows) | 1122 if (wp->w_winrow >= Rows) |
1122 wp->w_winrow = Rows - 1; | 1123 wp->w_winrow = Rows - 1; |
1123 } | 1124 } |
1124 | 1125 |
1125 if (wantcol == 0) | 1126 if (wantcol == 0) |
1126 center_hor = TRUE; | 1127 center_hor = TRUE; |
1127 else if (wp->w_popup_pos == POPPOS_TOPLEFT | 1128 else if (wantcol > 0 && (wp->w_popup_pos == POPPOS_TOPLEFT |
1128 || wp->w_popup_pos == POPPOS_BOTLEFT) | 1129 || wp->w_popup_pos == POPPOS_BOTLEFT)) |
1129 { | 1130 { |
1130 wp->w_wincol = wantcol - 1; | 1131 wp->w_wincol = wantcol - 1; |
1131 if (wp->w_wincol >= Columns - 3) | 1132 if (wp->w_wincol >= Columns - 3) |
1132 wp->w_wincol = Columns - 3; | 1133 wp->w_wincol = Columns - 3; |
1133 } | 1134 } |
3585 * Return TRUE if a popup was closed. | 3586 * Return TRUE if a popup was closed. |
3586 */ | 3587 */ |
3587 int | 3588 int |
3588 popup_win_closed(win_T *win) | 3589 popup_win_closed(win_T *win) |
3589 { | 3590 { |
3590 win_T *wp; | 3591 int round; |
3591 | 3592 win_T *wp; |
3592 for (wp = first_popupwin; wp != NULL; wp = wp->w_next) | 3593 win_T *next; |
3593 if (wp->w_popup_prop_win == win) | 3594 int ret = FALSE; |
3594 { | 3595 |
3595 popup_close_with_retval(wp, -1); | 3596 for (round = 1; round <= 2; ++round) |
3596 return TRUE; | 3597 for (wp = round == 1 ? first_popupwin : curtab->tp_first_popupwin; |
3597 } | 3598 wp != NULL; wp = next) |
3598 for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) | 3599 { |
3599 if (wp->w_popup_prop_win == win) | 3600 next = wp->w_next; |
3600 { | 3601 if (wp->w_popup_prop_win == win) |
3601 popup_close_with_retval(wp, -1); | 3602 { |
3602 return TRUE; | 3603 popup_close_with_retval(wp, -1); |
3603 } | 3604 ret = TRUE; |
3604 return FALSE; | 3605 } |
3606 } | |
3607 return ret; | |
3605 } | 3608 } |
3606 | 3609 |
3607 /* | 3610 /* |
3608 * Set the title of the popup window to the file name. | 3611 * Set the title of the popup window to the file name. |
3609 */ | 3612 */ |