Mercurial > vim
comparison src/popupwin.c @ 17767:c75da1064e33 v8.1.1880
patch 8.1.1880: cannot show extra info for completion in a popup window
commit https://github.com/vim/vim/commit/576a4a6ff14da876d7c4418e5f27e926fcfa8d2a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 18 15:25:17 2019 +0200
patch 8.1.1880: cannot show extra info for completion in a popup window
Problem: Cannot show extra info for completion in a popup window.
Solution: Add the "popup" entry in 'completeopt'.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 18 Aug 2019 15:30:06 +0200 |
parents | 6e6a84993444 |
children | 4bd21046902b |
comparison
equal
deleted
inserted
replaced
17766:be00d5dad3f5 | 17767:c75da1064e33 |
---|---|
949 */ | 949 */ |
950 int | 950 int |
951 popup_height(win_T *wp) | 951 popup_height(win_T *wp) |
952 { | 952 { |
953 return wp->w_height | 953 return wp->w_height |
954 + popup_top_extra(wp) | 954 + popup_top_extra(wp) |
955 + wp->w_popup_padding[2] + wp->w_popup_border[2]; | 955 + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
956 } | 956 } |
957 | 957 |
958 /* | 958 /* |
959 * Return the width of popup window "wp", including border, padding and | 959 * Return the width of popup window "wp", including border, padding and |
960 * scrollbar. | 960 * scrollbar. |
963 popup_width(win_T *wp) | 963 popup_width(win_T *wp) |
964 { | 964 { |
965 // w_leftcol is how many columns of the core are left of the screen | 965 // w_leftcol is how many columns of the core are left of the screen |
966 // w_popup_rightoff is how many columns of the core are right of the screen | 966 // w_popup_rightoff is how many columns of the core are right of the screen |
967 return wp->w_width + wp->w_leftcol | 967 return wp->w_width + wp->w_leftcol |
968 + wp->w_popup_padding[3] + wp->w_popup_border[3] | 968 + popup_extra_width(wp) |
969 + wp->w_popup_padding[1] + wp->w_popup_border[1] | 969 + wp->w_popup_rightoff; |
970 + wp->w_has_scrollbar | 970 } |
971 + wp->w_popup_rightoff; | 971 |
972 /* | |
973 * Return the extra width of popup window "wp": border, padding and scrollbar. | |
974 */ | |
975 int | |
976 popup_extra_width(win_T *wp) | |
977 { | |
978 return wp->w_popup_padding[3] + wp->w_popup_border[3] | |
979 + wp->w_popup_padding[1] + wp->w_popup_border[1] | |
980 + wp->w_has_scrollbar; | |
972 } | 981 } |
973 | 982 |
974 /* | 983 /* |
975 * Adjust the position and size of the popup to fit on the screen. | 984 * Adjust the position and size of the popup to fit on the screen. |
976 */ | 985 */ |
1228 TYPE_ATCURSOR, | 1237 TYPE_ATCURSOR, |
1229 TYPE_BEVAL, | 1238 TYPE_BEVAL, |
1230 TYPE_NOTIFICATION, | 1239 TYPE_NOTIFICATION, |
1231 TYPE_DIALOG, | 1240 TYPE_DIALOG, |
1232 TYPE_MENU, | 1241 TYPE_MENU, |
1233 TYPE_PREVIEW | 1242 TYPE_PREVIEW, // preview window |
1243 TYPE_INFO // popup menu info | |
1234 } create_type_T; | 1244 } create_type_T; |
1235 | 1245 |
1236 /* | 1246 /* |
1237 * Make "buf" empty and set the contents to "text". | 1247 * Make "buf" empty and set the contents to "text". |
1238 * Used by popup_create() and popup_settext(). | 1248 * Used by popup_create() and popup_settext(). |
1328 /* | 1338 /* |
1329 * Set w_wantline and w_wantcol for the cursor position in the current window. | 1339 * Set w_wantline and w_wantcol for the cursor position in the current window. |
1330 * Keep at least "width" columns from the right of the screen. | 1340 * Keep at least "width" columns from the right of the screen. |
1331 */ | 1341 */ |
1332 void | 1342 void |
1333 popup_set_wantpos(win_T *wp, int width) | 1343 popup_set_wantpos_cursor(win_T *wp, int width) |
1334 { | 1344 { |
1335 setcursor_mayforce(TRUE); | 1345 setcursor_mayforce(TRUE); |
1336 wp->w_wantline = curwin->w_winrow + curwin->w_wrow; | 1346 wp->w_wantline = curwin->w_winrow + curwin->w_wrow; |
1337 if (wp->w_wantline == 0) // cursor in first line | 1347 if (wp->w_wantline == 0) // cursor in first line |
1338 { | 1348 { |
1349 } | 1359 } |
1350 popup_adjust_position(wp); | 1360 popup_adjust_position(wp); |
1351 } | 1361 } |
1352 | 1362 |
1353 /* | 1363 /* |
1364 * Set w_wantline and w_wantcol for the a given screen position. | |
1365 * Caller must take care of running into the window border. | |
1366 */ | |
1367 void | |
1368 popup_set_wantpos_rowcol(win_T *wp, int row, int col) | |
1369 { | |
1370 wp->w_wantline = row; | |
1371 wp->w_wantcol = col; | |
1372 popup_adjust_position(wp); | |
1373 } | |
1374 | |
1375 /* | |
1376 * Add a border and lef&right padding. | |
1377 */ | |
1378 static void | |
1379 add_border_left_right_padding(win_T *wp) | |
1380 { | |
1381 int i; | |
1382 | |
1383 for (i = 0; i < 4; ++i) | |
1384 { | |
1385 wp->w_popup_border[i] = 1; | |
1386 wp->w_popup_padding[i] = (i & 1) ? 1 : 0; | |
1387 } | |
1388 } | |
1389 | |
1390 /* | |
1354 * popup_create({text}, {options}) | 1391 * popup_create({text}, {options}) |
1355 * popup_atcursor({text}, {options}) | 1392 * popup_atcursor({text}, {options}) |
1356 * etc. | 1393 * etc. |
1357 * When creating a preview window popup "argvars" and "rettv" are NULL. | 1394 * When creating a preview or info popup "argvars" and "rettv" are NULL. |
1358 */ | 1395 */ |
1359 static win_T * | 1396 static win_T * |
1360 popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) | 1397 popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) |
1361 { | 1398 { |
1362 win_T *wp; | 1399 win_T *wp; |
1493 { | 1530 { |
1494 wp->w_popup_pos = POPPOS_BOTLEFT; | 1531 wp->w_popup_pos = POPPOS_BOTLEFT; |
1495 } | 1532 } |
1496 if (type == TYPE_ATCURSOR) | 1533 if (type == TYPE_ATCURSOR) |
1497 { | 1534 { |
1498 popup_set_wantpos(wp, 0); | 1535 popup_set_wantpos_cursor(wp, 0); |
1499 set_moved_values(wp); | 1536 set_moved_values(wp); |
1500 set_moved_columns(wp, FIND_STRING); | 1537 set_moved_columns(wp, FIND_STRING); |
1501 } | 1538 } |
1502 | 1539 |
1503 if (type == TYPE_BEVAL) | 1540 if (type == TYPE_BEVAL) |
1569 { | 1606 { |
1570 wp->w_popup_pos = POPPOS_CENTER; | 1607 wp->w_popup_pos = POPPOS_CENTER; |
1571 wp->w_zindex = POPUPWIN_DIALOG_ZINDEX; | 1608 wp->w_zindex = POPUPWIN_DIALOG_ZINDEX; |
1572 wp->w_popup_flags |= POPF_DRAG; | 1609 wp->w_popup_flags |= POPF_DRAG; |
1573 wp->w_popup_flags &= ~POPF_MAPPING; | 1610 wp->w_popup_flags &= ~POPF_MAPPING; |
1574 for (i = 0; i < 4; ++i) | 1611 add_border_left_right_padding(wp); |
1575 { | |
1576 wp->w_popup_border[i] = 1; | |
1577 wp->w_popup_padding[i] = (i & 1) ? 1 : 0; | |
1578 } | |
1579 } | 1612 } |
1580 | 1613 |
1581 if (type == TYPE_MENU) | 1614 if (type == TYPE_MENU) |
1582 { | 1615 { |
1583 typval_T tv; | 1616 typval_T tv; |
1598 wp->w_popup_flags |= POPF_DRAG | POPF_RESIZE; | 1631 wp->w_popup_flags |= POPF_DRAG | POPF_RESIZE; |
1599 wp->w_popup_close = POPCLOSE_BUTTON; | 1632 wp->w_popup_close = POPCLOSE_BUTTON; |
1600 for (i = 0; i < 4; ++i) | 1633 for (i = 0; i < 4; ++i) |
1601 wp->w_popup_border[i] = 1; | 1634 wp->w_popup_border[i] = 1; |
1602 parse_previewpopup(wp); | 1635 parse_previewpopup(wp); |
1603 popup_set_wantpos(wp, wp->w_minwidth); | 1636 popup_set_wantpos_cursor(wp, wp->w_minwidth); |
1637 } | |
1638 if (type == TYPE_INFO) | |
1639 { | |
1640 wp->w_popup_pos = POPPOS_TOPLEFT; | |
1641 wp->w_popup_flags |= POPF_DRAG | POPF_RESIZE; | |
1642 wp->w_popup_close = POPCLOSE_BUTTON; | |
1643 add_border_left_right_padding(wp); | |
1604 } | 1644 } |
1605 | 1645 |
1606 for (i = 0; i < 4; ++i) | 1646 for (i = 0; i < 4; ++i) |
1607 VIM_CLEAR(wp->w_border_highlight[i]); | 1647 VIM_CLEAR(wp->w_border_highlight[i]); |
1608 for (i = 0; i < 8; ++i) | 1648 for (i = 0; i < 8; ++i) |
3169 if (wp->w_p_pvw) | 3209 if (wp->w_p_pvw) |
3170 return wp; | 3210 return wp; |
3171 return NULL; | 3211 return NULL; |
3172 } | 3212 } |
3173 | 3213 |
3174 void | |
3175 f_popup_getpreview(typval_T *argvars UNUSED, typval_T *rettv) | |
3176 { | |
3177 win_T *wp = popup_find_preview_window(); | |
3178 | |
3179 rettv->vval.v_number = wp == NULL ? 0 : wp->w_id; | |
3180 } | |
3181 | |
3182 int | 3214 int |
3183 popup_is_popup(win_T *wp) | 3215 popup_is_popup(win_T *wp) |
3184 { | 3216 { |
3185 return wp->w_popup_flags != 0; | 3217 return wp->w_popup_flags != 0; |
3186 } | 3218 } |
3187 | 3219 |
3188 /* | 3220 /* |
3189 * Create a popup to be used as the preview window. | 3221 * Find an existing popup used as the info window, in the current tab page. |
3222 * Return NULL if not found. | |
3223 */ | |
3224 win_T * | |
3225 popup_find_info_window(void) | |
3226 { | |
3227 win_T *wp; | |
3228 | |
3229 // info window popup is always local to tab page. | |
3230 for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) | |
3231 if (wp->w_popup_flags & POPF_INFO) | |
3232 return wp; | |
3233 return NULL; | |
3234 } | |
3235 | |
3236 void | |
3237 f_popup_getpreview(typval_T *argvars UNUSED, typval_T *rettv) | |
3238 { | |
3239 win_T *wp = popup_find_preview_window(); | |
3240 | |
3241 rettv->vval.v_number = wp == NULL ? 0 : wp->w_id; | |
3242 } | |
3243 | |
3244 /* | |
3245 * Create a popup to be used as the preview or info window. | |
3190 * NOTE: this makes the popup the current window, so that the file can be | 3246 * NOTE: this makes the popup the current window, so that the file can be |
3191 * edited. However, it must not remain to be the current window, the caller | 3247 * edited. However, it must not remain to be the current window, the caller |
3192 * must make sure of that. | 3248 * must make sure of that. |
3193 */ | 3249 */ |
3194 int | 3250 int |
3195 popup_create_preview_window(void) | 3251 popup_create_preview_window(int info) |
3196 { | 3252 { |
3197 win_T *wp = popup_create(NULL, NULL, TYPE_PREVIEW); | 3253 win_T *wp = popup_create(NULL, NULL, info ? TYPE_INFO : TYPE_PREVIEW); |
3198 | 3254 |
3199 if (wp == NULL) | 3255 if (wp == NULL) |
3200 return FAIL; | 3256 return FAIL; |
3201 wp->w_p_pvw = TRUE; | 3257 if (info) |
3258 wp->w_popup_flags |= POPF_INFO; | |
3259 else | |
3260 wp->w_p_pvw = TRUE; | |
3202 | 3261 |
3203 // Set the width to a reasonable value, so that w_topline can be computed. | 3262 // Set the width to a reasonable value, so that w_topline can be computed. |
3204 if (wp->w_minwidth > 0) | 3263 if (wp->w_minwidth > 0) |
3205 wp->w_width = wp->w_minwidth; | 3264 wp->w_width = wp->w_minwidth; |
3206 else if (wp->w_maxwidth > 0) | 3265 else if (wp->w_maxwidth > 0) |
3214 win_enter(wp, FALSE); | 3273 win_enter(wp, FALSE); |
3215 return OK; | 3274 return OK; |
3216 } | 3275 } |
3217 | 3276 |
3218 void | 3277 void |
3219 popup_close_preview() | 3278 popup_close_preview(int info) |
3220 { | 3279 { |
3221 win_T *wp = popup_find_preview_window(); | 3280 win_T *wp = info ? popup_find_info_window() : popup_find_preview_window(); |
3222 | 3281 |
3223 if (wp != NULL) | 3282 if (wp != NULL) |
3224 { | 3283 { |
3225 typval_T res; | 3284 typval_T res; |
3226 | 3285 |