Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read a list of people who contributed. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Implementation of popup windows. See ":help popup". |
| 12 | */ |
| 13 | |
| 14 | #include "vim.h" |
| 15 | |
| 16 | #ifdef FEAT_TEXT_PROP |
| 17 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 18 | typedef struct { |
| 19 | char *pp_name; |
| 20 | poppos_T pp_val; |
| 21 | } poppos_entry_T; |
| 22 | |
| 23 | static poppos_entry_T poppos_entries[] = { |
| 24 | {"botleft", POPPOS_BOTLEFT}, |
| 25 | {"topleft", POPPOS_TOPLEFT}, |
| 26 | {"botright", POPPOS_BOTRIGHT}, |
| 27 | {"topright", POPPOS_TOPRIGHT}, |
| 28 | {"center", POPPOS_CENTER} |
| 29 | }; |
| 30 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 31 | /* |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 32 | * Get option value for "key", which is "line" or "col". |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 33 | * Handles "cursor+N" and "cursor-N". |
| 34 | */ |
| 35 | static int |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 36 | popup_options_one(dict_T *dict, char_u *key) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 37 | { |
| 38 | dictitem_T *di; |
| 39 | char_u *val; |
| 40 | char_u *s; |
| 41 | char_u *endp; |
| 42 | int n = 0; |
| 43 | |
| 44 | di = dict_find(dict, key, -1); |
| 45 | if (di == NULL) |
| 46 | return 0; |
| 47 | |
| 48 | val = tv_get_string(&di->di_tv); |
| 49 | if (STRNCMP(val, "cursor", 6) != 0) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 50 | return dict_get_number_check(dict, key); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 51 | |
| 52 | setcursor_mayforce(TRUE); |
| 53 | s = val + 6; |
| 54 | if (*s != NUL) |
| 55 | { |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 56 | endp = s; |
| 57 | if (*skipwhite(s) == '+' || *skipwhite(s) == '-') |
| 58 | n = strtol((char *)s, (char **)&endp, 10); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 59 | if (endp != NULL && *skipwhite(endp) != NUL) |
| 60 | { |
| 61 | semsg(_(e_invexpr2), val); |
| 62 | return 0; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (STRCMP(key, "line") == 0) |
| 67 | n = screen_screenrow() + 1 + n; |
| 68 | else // "col" |
| 69 | n = screen_screencol() + 1 + n; |
| 70 | |
| 71 | if (n < 1) |
| 72 | n = 1; |
| 73 | return n; |
| 74 | } |
| 75 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 76 | static void |
| 77 | get_pos_options(win_T *wp, dict_T *dict) |
| 78 | { |
| 79 | char_u *str; |
| 80 | int nr; |
| 81 | |
| 82 | nr = popup_options_one(dict, (char_u *)"line"); |
| 83 | if (nr > 0) |
| 84 | wp->w_wantline = nr; |
| 85 | nr = popup_options_one(dict, (char_u *)"col"); |
| 86 | if (nr > 0) |
| 87 | wp->w_wantcol = nr; |
| 88 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 89 | wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0; |
| 90 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 91 | str = dict_get_string(dict, (char_u *)"pos", FALSE); |
| 92 | if (str != NULL) |
| 93 | { |
| 94 | for (nr = 0; |
| 95 | nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); |
| 96 | ++nr) |
| 97 | if (STRCMP(str, poppos_entries[nr].pp_name) == 0) |
| 98 | { |
| 99 | wp->w_popup_pos = poppos_entries[nr].pp_val; |
| 100 | nr = -1; |
| 101 | break; |
| 102 | } |
| 103 | if (nr != -1) |
| 104 | semsg(_(e_invarg2), str); |
| 105 | } |
| 106 | } |
| 107 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 108 | static void |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 109 | set_padding_border(dict_T *dict, int *array, char *name, int max_val) |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 110 | { |
| 111 | dictitem_T *di; |
| 112 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 113 | di = dict_find(dict, (char_u *)name, -1); |
| 114 | if (di != NULL) |
| 115 | { |
| 116 | if (di->di_tv.v_type != VAR_LIST) |
| 117 | emsg(_(e_listreq)); |
| 118 | else |
| 119 | { |
| 120 | list_T *list = di->di_tv.vval.v_list; |
| 121 | listitem_T *li; |
| 122 | int i; |
| 123 | int nr; |
| 124 | |
| 125 | for (i = 0; i < 4; ++i) |
| 126 | array[i] = 1; |
| 127 | if (list != NULL) |
| 128 | for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; |
| 129 | ++i, li = li->li_next) |
| 130 | { |
| 131 | nr = (int)tv_get_number(&li->li_tv); |
| 132 | if (nr >= 0) |
| 133 | array[i] = nr > max_val ? max_val : nr; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 139 | /* |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 140 | * Used when popup options contain "moved": set default moved values. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 141 | */ |
| 142 | static void |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 143 | set_moved_values(win_T *wp) |
| 144 | { |
| 145 | wp->w_popup_curwin = curwin; |
| 146 | wp->w_popup_lnum = curwin->w_cursor.lnum; |
| 147 | wp->w_popup_mincol = curwin->w_cursor.col; |
| 148 | wp->w_popup_maxcol = curwin->w_cursor.col; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Used when popup options contain "moved" with "word" or "WORD". |
| 153 | */ |
| 154 | static void |
| 155 | set_moved_columns(win_T *wp, int flags) |
| 156 | { |
| 157 | char_u *ptr; |
| 158 | int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR); |
| 159 | |
| 160 | if (len > 0) |
| 161 | { |
| 162 | wp->w_popup_mincol = (int)(ptr - ml_get_curline()); |
| 163 | wp->w_popup_maxcol = wp->w_popup_mincol + len - 1; |
| 164 | } |
| 165 | } |
| 166 | |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 167 | /* |
| 168 | * Return TRUE if "row"/"col" is on the border of the popup. |
| 169 | * The values are relative to the top-left corner. |
| 170 | */ |
| 171 | int |
| 172 | popup_on_border(win_T *wp, int row, int col) |
| 173 | { |
| 174 | return (row == 0 && wp->w_popup_border[0] > 0) |
| 175 | || (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0) |
| 176 | || (col == 0 && wp->w_popup_border[3] > 0) |
| 177 | || (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0); |
| 178 | } |
| 179 | |
| 180 | // Values set when dragging a popup window starts. |
| 181 | static int drag_start_row; |
| 182 | static int drag_start_col; |
| 183 | static int drag_start_wantline; |
| 184 | static int drag_start_wantcol; |
| 185 | |
| 186 | /* |
| 187 | * Mouse down on border of popup window: start dragging it. |
| 188 | * Uses mouse_col and mouse_row. |
| 189 | */ |
| 190 | void |
| 191 | popup_start_drag(win_T *wp) |
| 192 | { |
| 193 | drag_start_row = mouse_row; |
| 194 | drag_start_col = mouse_col; |
| 195 | // TODO: handle using different corner |
| 196 | if (wp->w_wantline == 0) |
| 197 | drag_start_wantline = wp->w_winrow + 1; |
| 198 | else |
| 199 | drag_start_wantline = wp->w_wantline; |
| 200 | if (wp->w_wantcol == 0) |
| 201 | drag_start_wantcol = wp->w_wincol + 1; |
| 202 | else |
| 203 | drag_start_wantcol = wp->w_wantcol; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 204 | |
| 205 | // Stop centering the popup |
| 206 | if (wp->w_popup_pos == POPPOS_CENTER) |
| 207 | wp->w_popup_pos = POPPOS_TOPLEFT; |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* |
| 211 | * Mouse moved while dragging a popup window: adjust the window popup position. |
| 212 | */ |
| 213 | void |
| 214 | popup_drag(win_T *wp) |
| 215 | { |
| 216 | // The popup may be closed before dragging stops. |
| 217 | if (!win_valid_popup(wp)) |
| 218 | return; |
| 219 | |
| 220 | wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); |
| 221 | if (wp->w_wantline < 1) |
| 222 | wp->w_wantline = 1; |
| 223 | if (wp->w_wantline > Rows) |
| 224 | wp->w_wantline = Rows; |
| 225 | wp->w_wantcol = drag_start_wantcol + (mouse_col - drag_start_col); |
| 226 | if (wp->w_wantcol < 1) |
| 227 | wp->w_wantcol = 1; |
| 228 | if (wp->w_wantcol > Columns) |
| 229 | wp->w_wantcol = Columns; |
| 230 | |
| 231 | popup_adjust_position(wp); |
| 232 | } |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 233 | |
| 234 | #if defined(FEAT_TIMERS) |
| 235 | static void |
| 236 | popup_add_timeout(win_T *wp, int time) |
| 237 | { |
| 238 | char_u cbbuf[50]; |
| 239 | char_u *ptr = cbbuf; |
| 240 | typval_T tv; |
| 241 | |
| 242 | vim_snprintf((char *)cbbuf, sizeof(cbbuf), |
| 243 | "{_ -> popup_close(%d)}", wp->w_id); |
| 244 | if (get_lambda_tv(&ptr, &tv, TRUE) == OK) |
| 245 | { |
| 246 | wp->w_popup_timer = create_timer(time, 0); |
| 247 | wp->w_popup_timer->tr_callback = get_callback(&tv); |
| 248 | clear_tv(&tv); |
| 249 | } |
| 250 | } |
| 251 | #endif |
| 252 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 253 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 254 | * Shared between popup_create() and f_popup_move(). |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 255 | */ |
| 256 | static void |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 257 | apply_move_options(win_T *wp, dict_T *d) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 258 | { |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 259 | int nr; |
| 260 | |
| 261 | if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0) |
| 262 | wp->w_minwidth = nr; |
| 263 | if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0) |
| 264 | wp->w_minheight = nr; |
| 265 | if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0) |
| 266 | wp->w_maxwidth = nr; |
| 267 | if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) |
| 268 | wp->w_maxheight = nr; |
| 269 | get_pos_options(wp, d); |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Shared between popup_create() and f_popup_setoptions(). |
| 274 | */ |
| 275 | static void |
| 276 | apply_general_options(win_T *wp, dict_T *dict) |
| 277 | { |
| 278 | dictitem_T *di; |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 279 | int nr; |
| 280 | char_u *str; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 281 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 282 | // TODO: flip |
| 283 | |
| 284 | di = dict_find(dict, (char_u *)"firstline", -1); |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 285 | if (di != NULL) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 286 | wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); |
| 287 | if (wp->w_firstline < 1) |
| 288 | wp->w_firstline = 1; |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 289 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 290 | di = dict_find(dict, (char_u *)"scrollbar", -1); |
| 291 | if (di != NULL) |
| 292 | wp->w_want_scrollbar = dict_get_number(dict, (char_u *)"scrollbar"); |
| 293 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 294 | str = dict_get_string(dict, (char_u *)"title", FALSE); |
| 295 | if (str != NULL) |
| 296 | { |
| 297 | vim_free(wp->w_popup_title); |
| 298 | wp->w_popup_title = vim_strsave(str); |
| 299 | } |
| 300 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 301 | di = dict_find(dict, (char_u *)"wrap", -1); |
| 302 | if (di != NULL) |
| 303 | { |
| 304 | nr = dict_get_number(dict, (char_u *)"wrap"); |
| 305 | wp->w_p_wrap = nr != 0; |
| 306 | } |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 307 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 308 | di = dict_find(dict, (char_u *)"drag", -1); |
| 309 | if (di != NULL) |
| 310 | wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag"); |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 311 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 312 | str = dict_get_string(dict, (char_u *)"highlight", FALSE); |
| 313 | if (str != NULL) |
| 314 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
| 315 | str, OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 316 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 317 | set_padding_border(dict, wp->w_popup_padding, "padding", 999); |
| 318 | set_padding_border(dict, wp->w_popup_border, "border", 1); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 319 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 320 | di = dict_find(dict, (char_u *)"borderhighlight", -1); |
| 321 | if (di != NULL) |
| 322 | { |
| 323 | if (di->di_tv.v_type != VAR_LIST) |
| 324 | emsg(_(e_listreq)); |
| 325 | else |
| 326 | { |
| 327 | list_T *list = di->di_tv.vval.v_list; |
| 328 | listitem_T *li; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 329 | int i; |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 330 | |
| 331 | if (list != NULL) |
| 332 | for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; |
| 333 | ++i, li = li->li_next) |
| 334 | { |
| 335 | str = tv_get_string(&li->li_tv); |
| 336 | if (*str != NUL) |
| 337 | wp->w_border_highlight[i] = vim_strsave(str); |
| 338 | } |
| 339 | if (list->lv_len == 1 && wp->w_border_highlight[0] != NULL) |
| 340 | for (i = 1; i < 4; ++i) |
| 341 | wp->w_border_highlight[i] = |
| 342 | vim_strsave(wp->w_border_highlight[0]); |
| 343 | } |
| 344 | } |
| 345 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 346 | di = dict_find(dict, (char_u *)"borderchars", -1); |
| 347 | if (di != NULL) |
| 348 | { |
| 349 | if (di->di_tv.v_type != VAR_LIST) |
| 350 | emsg(_(e_listreq)); |
| 351 | else |
| 352 | { |
| 353 | list_T *list = di->di_tv.vval.v_list; |
| 354 | listitem_T *li; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 355 | int i; |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 356 | |
| 357 | if (list != NULL) |
| 358 | for (i = 0, li = list->lv_first; i < 8 && i < list->lv_len; |
| 359 | ++i, li = li->li_next) |
| 360 | { |
| 361 | str = tv_get_string(&li->li_tv); |
| 362 | if (*str != NUL) |
| 363 | wp->w_border_char[i] = mb_ptr2char(str); |
| 364 | } |
| 365 | if (list->lv_len == 1) |
| 366 | for (i = 1; i < 8; ++i) |
| 367 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 368 | if (list->lv_len == 2) |
| 369 | { |
| 370 | for (i = 4; i < 8; ++i) |
| 371 | wp->w_border_char[i] = wp->w_border_char[1]; |
| 372 | for (i = 1; i < 4; ++i) |
| 373 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 374 | } |
| 375 | } |
| 376 | } |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 377 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 378 | di = dict_find(dict, (char_u *)"zindex", -1); |
| 379 | if (di != NULL) |
| 380 | { |
| 381 | wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); |
| 382 | if (wp->w_zindex < 1) |
| 383 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
| 384 | if (wp->w_zindex > 32000) |
| 385 | wp->w_zindex = 32000; |
| 386 | } |
| 387 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 388 | di = dict_find(dict, (char_u *)"mask", -1); |
| 389 | if (di != NULL) |
| 390 | { |
| 391 | int ok = TRUE; |
| 392 | |
| 393 | if (di->di_tv.v_type != VAR_LIST) |
| 394 | ok = FALSE; |
| 395 | else if (di->di_tv.vval.v_list != NULL) |
| 396 | { |
| 397 | listitem_T *li; |
| 398 | |
| 399 | for (li = di->di_tv.vval.v_list->lv_first; li != NULL; |
| 400 | li = li->li_next) |
| 401 | { |
| 402 | if (li->li_tv.v_type != VAR_LIST |
| 403 | || li->li_tv.vval.v_list == NULL |
| 404 | || li->li_tv.vval.v_list->lv_len != 4) |
| 405 | { |
| 406 | ok = FALSE; |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | if (ok) |
| 412 | { |
| 413 | wp->w_popup_mask = di->di_tv.vval.v_list; |
| 414 | ++wp->w_popup_mask->lv_refcount; |
| 415 | } |
| 416 | else |
| 417 | semsg(_(e_invargval), "mask"); |
| 418 | } |
| 419 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 420 | #if defined(FEAT_TIMERS) |
| 421 | // Add timer to close the popup after some time. |
| 422 | nr = dict_get_number(dict, (char_u *)"time"); |
| 423 | if (nr > 0) |
| 424 | popup_add_timeout(wp, nr); |
| 425 | #endif |
| 426 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 427 | di = dict_find(dict, (char_u *)"moved", -1); |
| 428 | if (di != NULL) |
| 429 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 430 | set_moved_values(wp); |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 431 | if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL) |
| 432 | { |
| 433 | char_u *s = di->di_tv.vval.v_string; |
| 434 | int flags = 0; |
| 435 | |
| 436 | if (STRCMP(s, "word") == 0) |
| 437 | flags = FIND_IDENT | FIND_STRING; |
| 438 | else if (STRCMP(s, "WORD") == 0) |
| 439 | flags = FIND_STRING; |
| 440 | else if (STRCMP(s, "any") != 0) |
| 441 | semsg(_(e_invarg2), s); |
| 442 | if (flags != 0) |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 443 | set_moved_columns(wp, flags); |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 444 | } |
| 445 | else if (di->di_tv.v_type == VAR_LIST |
| 446 | && di->di_tv.vval.v_list != NULL |
| 447 | && di->di_tv.vval.v_list->lv_len == 2) |
| 448 | { |
| 449 | list_T *l = di->di_tv.vval.v_list; |
| 450 | |
| 451 | wp->w_popup_mincol = tv_get_number(&l->lv_first->li_tv); |
| 452 | wp->w_popup_maxcol = tv_get_number(&l->lv_first->li_next->li_tv); |
| 453 | } |
| 454 | else |
| 455 | semsg(_(e_invarg2), tv_get_string(&di->di_tv)); |
| 456 | } |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 457 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 458 | di = dict_find(dict, (char_u *)"filter", -1); |
| 459 | if (di != NULL) |
| 460 | { |
| 461 | callback_T callback = get_callback(&di->di_tv); |
| 462 | |
| 463 | if (callback.cb_name != NULL) |
| 464 | { |
| 465 | free_callback(&wp->w_filter_cb); |
| 466 | set_callback(&wp->w_filter_cb, &callback); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | di = dict_find(dict, (char_u *)"callback", -1); |
| 471 | if (di != NULL) |
| 472 | { |
| 473 | callback_T callback = get_callback(&di->di_tv); |
| 474 | |
| 475 | if (callback.cb_name != NULL) |
| 476 | { |
| 477 | free_callback(&wp->w_close_cb); |
| 478 | set_callback(&wp->w_close_cb, &callback); |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * Go through the options in "dict" and apply them to popup window "wp". |
| 485 | */ |
| 486 | static void |
| 487 | apply_options(win_T *wp, dict_T *dict) |
| 488 | { |
| 489 | int nr; |
| 490 | |
| 491 | apply_move_options(wp, dict); |
| 492 | apply_general_options(wp, dict); |
| 493 | |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 494 | nr = dict_get_number(dict, (char_u *)"hidden"); |
| 495 | if (nr > 0) |
| 496 | { |
| 497 | wp->w_popup_flags |= POPF_HIDDEN; |
| 498 | --wp->w_buffer->b_nwindows; |
| 499 | } |
| 500 | |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 501 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /* |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 505 | * Add lines to the popup from a list of strings. |
| 506 | */ |
| 507 | static void |
| 508 | add_popup_strings(buf_T *buf, list_T *l) |
| 509 | { |
| 510 | listitem_T *li; |
| 511 | linenr_T lnum = 0; |
| 512 | char_u *p; |
| 513 | |
| 514 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 515 | if (li->li_tv.v_type == VAR_STRING) |
| 516 | { |
| 517 | p = li->li_tv.vval.v_string; |
| 518 | ml_append_buf(buf, lnum++, |
| 519 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Add lines to the popup from a list of dictionaries. |
| 525 | */ |
| 526 | static void |
| 527 | add_popup_dicts(buf_T *buf, list_T *l) |
| 528 | { |
| 529 | listitem_T *li; |
| 530 | listitem_T *pli; |
| 531 | linenr_T lnum = 0; |
| 532 | char_u *p; |
| 533 | dict_T *dict; |
| 534 | |
| 535 | // first add the text lines |
| 536 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 537 | { |
| 538 | if (li->li_tv.v_type != VAR_DICT) |
| 539 | { |
| 540 | emsg(_(e_dictreq)); |
| 541 | return; |
| 542 | } |
| 543 | dict = li->li_tv.vval.v_dict; |
| 544 | p = dict == NULL ? NULL |
| 545 | : dict_get_string(dict, (char_u *)"text", FALSE); |
| 546 | ml_append_buf(buf, lnum++, |
| 547 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 548 | } |
| 549 | |
| 550 | // add the text properties |
| 551 | lnum = 1; |
| 552 | for (li = l->lv_first; li != NULL; li = li->li_next, ++lnum) |
| 553 | { |
| 554 | dictitem_T *di; |
| 555 | list_T *plist; |
| 556 | |
| 557 | dict = li->li_tv.vval.v_dict; |
| 558 | di = dict_find(dict, (char_u *)"props", -1); |
| 559 | if (di != NULL) |
| 560 | { |
| 561 | if (di->di_tv.v_type != VAR_LIST) |
| 562 | { |
| 563 | emsg(_(e_listreq)); |
| 564 | return; |
| 565 | } |
| 566 | plist = di->di_tv.vval.v_list; |
| 567 | if (plist != NULL) |
| 568 | { |
| 569 | for (pli = plist->lv_first; pli != NULL; pli = pli->li_next) |
| 570 | { |
| 571 | if (pli->li_tv.v_type != VAR_DICT) |
| 572 | { |
| 573 | emsg(_(e_dictreq)); |
| 574 | return; |
| 575 | } |
| 576 | dict = pli->li_tv.vval.v_dict; |
| 577 | if (dict != NULL) |
| 578 | { |
| 579 | int col = dict_get_number(dict, (char_u *)"col"); |
| 580 | |
| 581 | prop_add_common( lnum, col, dict, buf, NULL); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /* |
Bram Moolenaar | 451d4b5 | 2019-06-12 20:22:27 +0200 | [diff] [blame] | 590 | * Return the height of popup window "wp", including border and padding. |
| 591 | */ |
| 592 | int |
| 593 | popup_height(win_T *wp) |
| 594 | { |
| 595 | return wp->w_height |
| 596 | + wp->w_popup_padding[0] + wp->w_popup_border[0] |
| 597 | + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
| 598 | } |
| 599 | |
| 600 | /* |
| 601 | * Return the width of popup window "wp", including border and padding. |
| 602 | */ |
| 603 | int |
| 604 | popup_width(win_T *wp) |
| 605 | { |
| 606 | return wp->w_width |
| 607 | + wp->w_popup_padding[3] + wp->w_popup_border[3] |
| 608 | + wp->w_popup_padding[1] + wp->w_popup_border[1]; |
| 609 | } |
| 610 | |
| 611 | /* |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 612 | * Get the padding plus border at the top, adjusted to 1 if there is a title. |
| 613 | */ |
| 614 | static int |
| 615 | popup_top_extra(win_T *wp) |
| 616 | { |
| 617 | int extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; |
| 618 | |
| 619 | if (extra == 0 && wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
| 620 | return 1; |
| 621 | return extra; |
| 622 | } |
| 623 | |
| 624 | /* |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 625 | * Adjust the position and size of the popup to fit on the screen. |
| 626 | */ |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 627 | void |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 628 | popup_adjust_position(win_T *wp) |
| 629 | { |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 630 | linenr_T lnum; |
| 631 | int wrapped = 0; |
| 632 | int maxwidth; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 633 | int center_vert = FALSE; |
| 634 | int center_hor = FALSE; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 635 | int allow_adjust_left = !wp->w_popup_fixed; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 636 | int top_extra = popup_top_extra(wp); |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 637 | int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1]; |
| 638 | int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2]; |
| 639 | int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 640 | int extra_height = top_extra + bot_extra; |
| 641 | int extra_width = left_extra + right_extra; |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 642 | int org_winrow = wp->w_winrow; |
| 643 | int org_wincol = wp->w_wincol; |
| 644 | int org_width = wp->w_width; |
| 645 | int org_height = wp->w_height; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 646 | int minwidth; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 647 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 648 | wp->w_winrow = 0; |
| 649 | wp->w_wincol = 0; |
| 650 | if (wp->w_popup_pos == POPPOS_CENTER) |
| 651 | { |
| 652 | // center after computing the size |
| 653 | center_vert = TRUE; |
| 654 | center_hor = TRUE; |
| 655 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 656 | else |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 657 | { |
| 658 | if (wp->w_wantline == 0) |
| 659 | center_vert = TRUE; |
| 660 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 661 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 662 | { |
| 663 | wp->w_winrow = wp->w_wantline - 1; |
| 664 | if (wp->w_winrow >= Rows) |
| 665 | wp->w_winrow = Rows - 1; |
| 666 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 667 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 668 | if (wp->w_wantcol == 0) |
| 669 | center_hor = TRUE; |
| 670 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 671 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 672 | { |
| 673 | wp->w_wincol = wp->w_wantcol - 1; |
| 674 | if (wp->w_wincol >= Columns - 3) |
| 675 | wp->w_wincol = Columns - 3; |
| 676 | } |
| 677 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 678 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 679 | // When centering or right aligned, use maximum width. |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 680 | // When left aligned use the space available, but shift to the left when we |
| 681 | // hit the right of the screen. |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 682 | maxwidth = Columns - wp->w_wincol - left_extra; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 683 | if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 684 | { |
| 685 | allow_adjust_left = FALSE; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 686 | maxwidth = wp->w_maxwidth; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 687 | } |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 688 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 689 | // start at the desired first line |
| 690 | wp->w_topline = wp->w_firstline; |
| 691 | if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) |
| 692 | wp->w_topline = wp->w_buffer->b_ml.ml_line_count; |
| 693 | |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 694 | // Compute width based on longest text line and the 'wrap' option. |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 695 | // Use a minimum width of one, so that something shows when there is no |
| 696 | // text. |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 697 | // TODO: more accurate wrapping |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 698 | wp->w_width = 1; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 699 | for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 700 | { |
| 701 | int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 702 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 703 | if (wp->w_p_wrap) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 704 | { |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 705 | while (len > maxwidth) |
| 706 | { |
| 707 | ++wrapped; |
| 708 | len -= maxwidth; |
| 709 | wp->w_width = maxwidth; |
| 710 | } |
| 711 | } |
| 712 | else if (len > maxwidth |
| 713 | && allow_adjust_left |
| 714 | && (wp->w_popup_pos == POPPOS_TOPLEFT |
| 715 | || wp->w_popup_pos == POPPOS_BOTLEFT)) |
| 716 | { |
| 717 | // adjust leftwise to fit text on screen |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 718 | int shift_by = len - maxwidth; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 719 | |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 720 | if (shift_by > wp->w_wincol) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 721 | { |
| 722 | int truncate_shift = shift_by - wp->w_wincol; |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 723 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 724 | len -= truncate_shift; |
| 725 | shift_by -= truncate_shift; |
| 726 | } |
| 727 | |
| 728 | wp->w_wincol -= shift_by; |
| 729 | maxwidth += shift_by; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 730 | wp->w_width = maxwidth; |
| 731 | } |
| 732 | if (wp->w_width < len) |
| 733 | wp->w_width = len; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 734 | // do not use the width of lines we're not going to show |
| 735 | if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count |
| 736 | - wp->w_topline + 1 + wrapped > wp->w_maxheight) |
| 737 | break; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 738 | } |
| 739 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 740 | wp->w_has_scrollbar = wp->w_want_scrollbar |
| 741 | && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); |
| 742 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 743 | minwidth = wp->w_minwidth; |
| 744 | if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
| 745 | { |
| 746 | int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; |
| 747 | |
| 748 | if (minwidth < title_len) |
| 749 | minwidth = title_len; |
| 750 | } |
| 751 | |
| 752 | if (minwidth > 0 && wp->w_width < minwidth) |
| 753 | wp->w_width = minwidth; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 754 | if (wp->w_width > maxwidth) |
| 755 | wp->w_width = maxwidth; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 756 | if (center_hor) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 757 | { |
| 758 | wp->w_wincol = (Columns - wp->w_width - extra_width) / 2; |
| 759 | if (wp->w_wincol < 0) |
| 760 | wp->w_wincol = 0; |
| 761 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 762 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 763 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 764 | { |
| 765 | // Right aligned: move to the right if needed. |
| 766 | // No truncation, because that would change the height. |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 767 | if (wp->w_width + extra_width < wp->w_wantcol) |
| 768 | wp->w_wincol = wp->w_wantcol - (wp->w_width + extra_width); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 769 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 770 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 771 | wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline |
| 772 | + 1 + wrapped; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 773 | if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) |
| 774 | wp->w_height = wp->w_minheight; |
| 775 | if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) |
| 776 | wp->w_height = wp->w_maxheight; |
| 777 | if (wp->w_height > Rows - wp->w_winrow) |
| 778 | wp->w_height = Rows - wp->w_winrow; |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 779 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 780 | if (center_vert) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 781 | { |
| 782 | wp->w_winrow = (Rows - wp->w_height - extra_height) / 2; |
| 783 | if (wp->w_winrow < 0) |
| 784 | wp->w_winrow = 0; |
| 785 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 786 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 787 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 788 | { |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 789 | if ((wp->w_height + extra_height) <= wp->w_wantline) |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 790 | // bottom aligned: may move down |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 791 | wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 792 | else |
| 793 | // not enough space, make top aligned |
| 794 | wp->w_winrow = wp->w_wantline + 1; |
| 795 | } |
| 796 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 797 | wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 798 | |
| 799 | // Need to update popup_mask if the position or size changed. |
Bram Moolenaar | acc682b | 2019-06-08 17:15:51 +0200 | [diff] [blame] | 800 | // And redraw windows that were behind the popup. |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 801 | if (org_winrow != wp->w_winrow |
| 802 | || org_wincol != wp->w_wincol |
| 803 | || org_width != wp->w_width |
| 804 | || org_height != wp->w_height) |
| 805 | { |
Bram Moolenaar | 4c063a0 | 2019-06-10 21:24:12 +0200 | [diff] [blame] | 806 | redraw_all_later(VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 807 | popup_mask_refresh = TRUE; |
| 808 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 809 | } |
| 810 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 811 | typedef enum |
| 812 | { |
| 813 | TYPE_NORMAL, |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 814 | TYPE_ATCURSOR, |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 815 | TYPE_NOTIFICATION, |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 816 | TYPE_DIALOG, |
| 817 | TYPE_MENU |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 818 | } create_type_T; |
| 819 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 820 | /* |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 821 | * Make "buf" empty and set the contents to "text". |
| 822 | * Used by popup_create() and popup_settext(). |
| 823 | */ |
| 824 | static void |
| 825 | popup_set_buffer_text(buf_T *buf, typval_T text) |
| 826 | { |
| 827 | int lnum; |
| 828 | |
| 829 | // Clear the buffer, then replace the lines. |
| 830 | curbuf = buf; |
| 831 | for (lnum = buf->b_ml.ml_line_count; lnum > 0; --lnum) |
| 832 | ml_delete(lnum, FALSE); |
| 833 | curbuf = curwin->w_buffer; |
| 834 | |
| 835 | // Add text to the buffer. |
| 836 | if (text.v_type == VAR_STRING) |
| 837 | { |
| 838 | // just a string |
| 839 | ml_append_buf(buf, 0, text.vval.v_string, (colnr_T)0, TRUE); |
| 840 | } |
| 841 | else |
| 842 | { |
| 843 | list_T *l = text.vval.v_list; |
| 844 | |
| 845 | if (l->lv_len > 0) |
| 846 | { |
| 847 | if (l->lv_first->li_tv.v_type == VAR_STRING) |
| 848 | // list of strings |
| 849 | add_popup_strings(buf, l); |
| 850 | else |
| 851 | // list of dictionaries |
| 852 | add_popup_dicts(buf, l); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | // delete the line that was in the empty buffer |
| 857 | curbuf = buf; |
| 858 | ml_delete(buf->b_ml.ml_line_count, FALSE); |
| 859 | curbuf = curwin->w_buffer; |
| 860 | } |
| 861 | |
| 862 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 863 | * popup_create({text}, {options}) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 864 | * popup_atcursor({text}, {options}) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 865 | */ |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 866 | static win_T * |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 867 | popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 868 | { |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 869 | win_T *wp; |
| 870 | tabpage_T *tp = NULL; |
| 871 | int tabnr; |
| 872 | buf_T *buf; |
| 873 | dict_T *d; |
| 874 | int nr; |
| 875 | int i; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 876 | |
| 877 | // Check arguments look OK. |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 878 | if (!(argvars[0].v_type == VAR_STRING && argvars[0].vval.v_string != NULL) |
| 879 | && !(argvars[0].v_type == VAR_LIST && argvars[0].vval.v_list != NULL)) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 880 | { |
| 881 | emsg(_(e_listreq)); |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 882 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 883 | } |
| 884 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 885 | { |
| 886 | emsg(_(e_dictreq)); |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 887 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 888 | } |
| 889 | d = argvars[1].vval.v_dict; |
| 890 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 891 | if (dict_find(d, (char_u *)"tabpage", -1) != NULL) |
| 892 | tabnr = (int)dict_get_number(d, (char_u *)"tabpage"); |
| 893 | else if (type == TYPE_NOTIFICATION) |
| 894 | tabnr = -1; // notifications are global by default |
| 895 | else |
| 896 | tabnr = 0; |
| 897 | if (tabnr > 0) |
| 898 | { |
| 899 | tp = find_tabpage(tabnr); |
| 900 | if (tp == NULL) |
| 901 | { |
Bram Moolenaar | b2cda0d | 2019-06-24 05:06:36 +0200 | [diff] [blame] | 902 | semsg(_("E997: Tabpage not found: %d"), tabnr); |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 903 | return NULL; |
| 904 | } |
| 905 | } |
| 906 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 907 | // Create the window and buffer. |
| 908 | wp = win_alloc_popup_win(); |
| 909 | if (wp == NULL) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 910 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 911 | rettv->vval.v_number = wp->w_id; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 912 | wp->w_popup_pos = POPPOS_TOPLEFT; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 913 | |
| 914 | buf = buflist_new(NULL, NULL, (linenr_T)0, BLN_NEW|BLN_LISTED|BLN_DUMMY); |
| 915 | if (buf == NULL) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 916 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 917 | ml_open(buf); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 918 | |
| 919 | win_init_popup_win(wp, buf); |
| 920 | |
| 921 | set_local_options_default(wp); |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 922 | set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1, |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 923 | (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 924 | set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1, |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 925 | (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 926 | buf->b_p_ul = -1; // no undo |
| 927 | buf->b_p_swf = FALSE; // no swap file |
| 928 | buf->b_p_bl = FALSE; // unlisted buffer |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 929 | buf->b_locked = TRUE; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 930 | wp->w_p_wrap = TRUE; // 'wrap' is default on |
| 931 | |
Bram Moolenaar | 54fabd4 | 2019-05-30 19:03:22 +0200 | [diff] [blame] | 932 | // Avoid that 'buftype' is reset when this buffer is entered. |
| 933 | buf->b_p_initialized = TRUE; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 934 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 935 | if (tp != NULL) |
| 936 | { |
| 937 | // popup on specified tab page |
| 938 | wp->w_next = tp->tp_first_popupwin; |
| 939 | tp->tp_first_popupwin = wp; |
| 940 | } |
| 941 | else if (tabnr == 0) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 942 | { |
Bram Moolenaar | fc06cbb | 2019-06-15 14:14:31 +0200 | [diff] [blame] | 943 | // popup on current tab page |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 944 | wp->w_next = curtab->tp_first_popupwin; |
| 945 | curtab->tp_first_popupwin = wp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 946 | } |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 947 | else // (tabnr < 0) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 948 | { |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 949 | win_T *prev = first_popupwin; |
| 950 | |
| 951 | // Global popup: add at the end, so that it gets displayed on top of |
| 952 | // older ones with the same zindex. Matters for notifications. |
| 953 | if (first_popupwin == NULL) |
| 954 | first_popupwin = wp; |
| 955 | else |
| 956 | { |
| 957 | while (prev->w_next != NULL) |
| 958 | prev = prev->w_next; |
| 959 | prev->w_next = wp; |
| 960 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 961 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 962 | |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 963 | popup_set_buffer_text(buf, argvars[0]); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 964 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 965 | if (type == TYPE_ATCURSOR) |
| 966 | { |
| 967 | wp->w_popup_pos = POPPOS_BOTLEFT; |
| 968 | setcursor_mayforce(TRUE); |
| 969 | wp->w_wantline = screen_screenrow(); |
| 970 | if (wp->w_wantline == 0) // cursor in first line |
| 971 | { |
| 972 | wp->w_wantline = 2; |
| 973 | wp->w_popup_pos = POPPOS_TOPLEFT; |
| 974 | } |
| 975 | wp->w_wantcol = screen_screencol() + 1; |
| 976 | set_moved_values(wp); |
| 977 | set_moved_columns(wp, FIND_STRING); |
| 978 | } |
| 979 | |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 980 | // set default values |
| 981 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
| 982 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 983 | if (type == TYPE_NOTIFICATION) |
| 984 | { |
| 985 | win_T *twp, *nextwin; |
| 986 | int height = buf->b_ml.ml_line_count + 3; |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 987 | |
| 988 | // Try to not overlap with another global popup. Guess we need 3 |
| 989 | // more screen lines than buffer lines. |
| 990 | wp->w_wantline = 1; |
| 991 | for (twp = first_popupwin; twp != NULL; twp = nextwin) |
| 992 | { |
| 993 | nextwin = twp->w_next; |
| 994 | if (twp != wp |
| 995 | && twp->w_zindex == POPUPWIN_NOTIFICATION_ZINDEX |
| 996 | && twp->w_winrow <= wp->w_wantline - 1 + height |
| 997 | && twp->w_winrow + popup_height(twp) > wp->w_wantline - 1) |
| 998 | { |
| 999 | // move to below this popup and restart the loop to check for |
| 1000 | // overlap with other popups |
| 1001 | wp->w_wantline = twp->w_winrow + popup_height(twp) + 1; |
| 1002 | nextwin = first_popupwin; |
| 1003 | } |
| 1004 | } |
| 1005 | if (wp->w_wantline + height > Rows) |
| 1006 | { |
| 1007 | // can't avoid overlap, put on top in the hope that message goes |
| 1008 | // away soon. |
| 1009 | wp->w_wantline = 1; |
| 1010 | } |
| 1011 | |
| 1012 | wp->w_wantcol = 10; |
| 1013 | wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX; |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1014 | wp->w_minwidth = 20; |
| 1015 | wp->w_popup_drag = 1; |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1016 | for (i = 0; i < 4; ++i) |
| 1017 | wp->w_popup_border[i] = 1; |
| 1018 | wp->w_popup_padding[1] = 1; |
| 1019 | wp->w_popup_padding[3] = 1; |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1020 | |
| 1021 | nr = syn_name2id((char_u *)"PopupNotification"); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1022 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1023 | (char_u *)(nr == 0 ? "WarningMsg" : "PopupNotification"), |
| 1024 | OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1027 | if (type == TYPE_DIALOG || type == TYPE_MENU) |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1028 | { |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1029 | wp->w_popup_pos = POPPOS_CENTER; |
| 1030 | wp->w_zindex = POPUPWIN_DIALOG_ZINDEX; |
| 1031 | wp->w_popup_drag = 1; |
| 1032 | for (i = 0; i < 4; ++i) |
| 1033 | { |
| 1034 | wp->w_popup_border[i] = 1; |
| 1035 | wp->w_popup_padding[i] = 1; |
| 1036 | } |
| 1037 | } |
| 1038 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1039 | if (type == TYPE_MENU) |
| 1040 | { |
| 1041 | typval_T tv; |
| 1042 | callback_T callback; |
| 1043 | |
| 1044 | tv.v_type = VAR_STRING; |
| 1045 | tv.vval.v_string = (char_u *)"popup_filter_menu"; |
| 1046 | callback = get_callback(&tv); |
| 1047 | if (callback.cb_name != NULL) |
| 1048 | set_callback(&wp->w_filter_cb, &callback); |
| 1049 | |
| 1050 | wp->w_p_wrap = 0; |
| 1051 | } |
| 1052 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1053 | for (i = 0; i < 4; ++i) |
| 1054 | VIM_CLEAR(wp->w_border_highlight[i]); |
| 1055 | for (i = 0; i < 8; ++i) |
| 1056 | wp->w_border_char[i] = 0; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1057 | wp->w_want_scrollbar = 1; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1058 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1059 | // Deal with options. |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1060 | apply_options(wp, argvars[1].vval.v_dict); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1061 | |
Bram Moolenaar | 0fcf26b | 2019-06-23 01:03:51 +0200 | [diff] [blame] | 1062 | #ifdef FEAT_TIMERS |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1063 | if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) |
| 1064 | popup_add_timeout(wp, 3000); |
Bram Moolenaar | 0fcf26b | 2019-06-23 01:03:51 +0200 | [diff] [blame] | 1065 | #endif |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1066 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1067 | popup_adjust_position(wp); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1068 | |
| 1069 | wp->w_vsep_width = 0; |
| 1070 | |
| 1071 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1072 | popup_mask_refresh = TRUE; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1073 | |
| 1074 | return wp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | /* |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1078 | * popup_clear() |
| 1079 | */ |
| 1080 | void |
| 1081 | f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
| 1082 | { |
| 1083 | close_all_popups(); |
| 1084 | } |
| 1085 | |
| 1086 | /* |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1087 | * popup_create({text}, {options}) |
| 1088 | */ |
| 1089 | void |
| 1090 | f_popup_create(typval_T *argvars, typval_T *rettv) |
| 1091 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1092 | popup_create(argvars, rettv, TYPE_NORMAL); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | /* |
| 1096 | * popup_atcursor({text}, {options}) |
| 1097 | */ |
| 1098 | void |
| 1099 | f_popup_atcursor(typval_T *argvars, typval_T *rettv) |
| 1100 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1101 | popup_create(argvars, rettv, TYPE_ATCURSOR); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /* |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1105 | * Invoke the close callback for window "wp" with value "result". |
| 1106 | * Careful: The callback may make "wp" invalid! |
| 1107 | */ |
| 1108 | static void |
| 1109 | invoke_popup_callback(win_T *wp, typval_T *result) |
| 1110 | { |
| 1111 | typval_T rettv; |
| 1112 | int dummy; |
| 1113 | typval_T argv[3]; |
| 1114 | |
| 1115 | argv[0].v_type = VAR_NUMBER; |
| 1116 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 1117 | |
| 1118 | if (result != NULL && result->v_type != VAR_UNKNOWN) |
| 1119 | copy_tv(result, &argv[1]); |
| 1120 | else |
| 1121 | { |
| 1122 | argv[1].v_type = VAR_NUMBER; |
| 1123 | argv[1].vval.v_number = 0; |
| 1124 | } |
| 1125 | |
| 1126 | argv[2].v_type = VAR_UNKNOWN; |
| 1127 | |
| 1128 | call_callback(&wp->w_close_cb, -1, |
| 1129 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
| 1130 | if (result != NULL) |
| 1131 | clear_tv(&argv[1]); |
| 1132 | clear_tv(&rettv); |
| 1133 | } |
| 1134 | |
| 1135 | /* |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1136 | * Close popup "wp" and invoke any close callback for it. |
| 1137 | */ |
| 1138 | static void |
| 1139 | popup_close_and_callback(win_T *wp, typval_T *arg) |
| 1140 | { |
| 1141 | int id = wp->w_id; |
| 1142 | |
| 1143 | if (wp->w_close_cb.cb_name != NULL) |
| 1144 | // Careful: This may make "wp" invalid. |
| 1145 | invoke_popup_callback(wp, arg); |
| 1146 | |
| 1147 | popup_close(id); |
| 1148 | } |
| 1149 | |
| 1150 | /* |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1151 | * In a filter: check if the typed key is a mouse event that is used for |
| 1152 | * dragging the popup. |
| 1153 | */ |
| 1154 | static void |
| 1155 | filter_handle_drag(win_T *wp, int c, typval_T *rettv) |
| 1156 | { |
| 1157 | int row = mouse_row; |
| 1158 | int col = mouse_col; |
| 1159 | |
| 1160 | if (wp->w_popup_drag |
| 1161 | && is_mouse_key(c) |
| 1162 | && (wp == popup_dragwin |
| 1163 | || wp == mouse_find_win(&row, &col, FIND_POPUP))) |
| 1164 | // do not consume the key, allow for dragging the popup |
| 1165 | rettv->vval.v_number = 0; |
| 1166 | } |
| 1167 | |
| 1168 | static void |
| 1169 | popup_highlight_curline(win_T *wp) |
| 1170 | { |
| 1171 | int id; |
| 1172 | char buf[100]; |
| 1173 | |
| 1174 | match_delete(wp, 1, FALSE); |
| 1175 | |
| 1176 | id = syn_name2id((char_u *)"PopupSelected"); |
| 1177 | vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum); |
| 1178 | match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"), |
| 1179 | (char_u *)buf, 10, 1, NULL, NULL); |
| 1180 | } |
| 1181 | |
| 1182 | /* |
| 1183 | * popup_filter_menu({text}, {options}) |
| 1184 | */ |
| 1185 | void |
| 1186 | f_popup_filter_menu(typval_T *argvars, typval_T *rettv) |
| 1187 | { |
| 1188 | int id = tv_get_number(&argvars[0]); |
| 1189 | win_T *wp = win_id2wp(id); |
| 1190 | char_u *key = tv_get_string(&argvars[1]); |
| 1191 | typval_T res; |
| 1192 | int c; |
| 1193 | linenr_T old_lnum; |
| 1194 | |
| 1195 | // If the popup has been closed do not consume the key. |
| 1196 | if (wp == NULL) |
| 1197 | return; |
| 1198 | |
| 1199 | c = *key; |
| 1200 | if (c == K_SPECIAL && key[1] != NUL) |
| 1201 | c = TO_SPECIAL(key[1], key[2]); |
| 1202 | |
| 1203 | // consume all keys until done |
| 1204 | rettv->vval.v_number = 1; |
| 1205 | res.v_type = VAR_NUMBER; |
| 1206 | |
| 1207 | old_lnum = wp->w_cursor.lnum; |
| 1208 | if ((c == 'k' || c == 'K' || c == K_UP) && wp->w_cursor.lnum > 1) |
| 1209 | --wp->w_cursor.lnum; |
| 1210 | if ((c == 'j' || c == 'J' || c == K_DOWN) |
| 1211 | && wp->w_cursor.lnum < wp->w_buffer->b_ml.ml_line_count) |
| 1212 | ++wp->w_cursor.lnum; |
| 1213 | if (old_lnum != wp->w_cursor.lnum) |
| 1214 | { |
| 1215 | popup_highlight_curline(wp); |
| 1216 | return; |
| 1217 | } |
| 1218 | |
| 1219 | if (c == 'x' || c == 'X' || c == ESC || c == Ctrl_C) |
| 1220 | { |
| 1221 | // Cancelled, invoke callback with -1 |
| 1222 | res.vval.v_number = -1; |
| 1223 | popup_close_and_callback(wp, &res); |
| 1224 | return; |
| 1225 | } |
| 1226 | if (c == ' ' || c == K_KENTER || c == CAR || c == NL) |
| 1227 | { |
| 1228 | // Invoke callback with current index. |
| 1229 | res.vval.v_number = wp->w_cursor.lnum; |
| 1230 | popup_close_and_callback(wp, &res); |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | filter_handle_drag(wp, c, rettv); |
| 1235 | } |
| 1236 | |
| 1237 | /* |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1238 | * popup_filter_yesno({text}, {options}) |
| 1239 | */ |
| 1240 | void |
| 1241 | f_popup_filter_yesno(typval_T *argvars, typval_T *rettv) |
| 1242 | { |
| 1243 | int id = tv_get_number(&argvars[0]); |
| 1244 | win_T *wp = win_id2wp(id); |
| 1245 | char_u *key = tv_get_string(&argvars[1]); |
| 1246 | typval_T res; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1247 | int c; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1248 | |
| 1249 | // If the popup has been closed don't consume the key. |
| 1250 | if (wp == NULL) |
| 1251 | return; |
| 1252 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1253 | c = *key; |
| 1254 | if (c == K_SPECIAL && key[1] != NUL) |
| 1255 | c = TO_SPECIAL(key[1], key[2]); |
| 1256 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1257 | // consume all keys until done |
| 1258 | rettv->vval.v_number = 1; |
| 1259 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1260 | if (c == 'y' || c == 'Y') |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1261 | res.vval.v_number = 1; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1262 | else if (c == 'n' || c == 'N' || c == 'x' || c == 'X' || c == ESC) |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1263 | res.vval.v_number = 0; |
| 1264 | else |
| 1265 | { |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1266 | filter_handle_drag(wp, c, rettv); |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1267 | return; |
| 1268 | } |
| 1269 | |
| 1270 | // Invoke callback |
| 1271 | res.v_type = VAR_NUMBER; |
| 1272 | popup_close_and_callback(wp, &res); |
| 1273 | } |
| 1274 | |
| 1275 | /* |
| 1276 | * popup_dialog({text}, {options}) |
| 1277 | */ |
| 1278 | void |
| 1279 | f_popup_dialog(typval_T *argvars, typval_T *rettv) |
| 1280 | { |
| 1281 | popup_create(argvars, rettv, TYPE_DIALOG); |
| 1282 | } |
| 1283 | |
| 1284 | /* |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1285 | * popup_menu({text}, {options}) |
| 1286 | */ |
| 1287 | void |
| 1288 | f_popup_menu(typval_T *argvars, typval_T *rettv) |
| 1289 | { |
| 1290 | win_T *wp = popup_create(argvars, rettv, TYPE_MENU); |
| 1291 | |
| 1292 | if (wp != NULL) |
| 1293 | popup_highlight_curline(wp); |
| 1294 | } |
| 1295 | |
| 1296 | /* |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1297 | * popup_notification({text}, {options}) |
| 1298 | */ |
| 1299 | void |
| 1300 | f_popup_notification(typval_T *argvars, typval_T *rettv) |
| 1301 | { |
| 1302 | popup_create(argvars, rettv, TYPE_NOTIFICATION); |
| 1303 | } |
| 1304 | |
| 1305 | /* |
| 1306 | * Find the popup window with window-ID "id". |
| 1307 | * If the popup window does not exist NULL is returned. |
| 1308 | * If the window is not a popup window, and error message is given. |
| 1309 | */ |
| 1310 | static win_T * |
| 1311 | find_popup_win(int id) |
| 1312 | { |
| 1313 | win_T *wp = win_id2wp(id); |
| 1314 | |
| 1315 | if (wp != NULL && !bt_popup(wp->w_buffer)) |
| 1316 | { |
| 1317 | semsg(_("E993: window %d is not a popup window"), id); |
| 1318 | return NULL; |
| 1319 | } |
| 1320 | return wp; |
| 1321 | } |
| 1322 | |
| 1323 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1324 | * popup_close({id}) |
| 1325 | */ |
| 1326 | void |
| 1327 | f_popup_close(typval_T *argvars, typval_T *rettv UNUSED) |
| 1328 | { |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1329 | int id = (int)tv_get_number(argvars); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1330 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1331 | |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1332 | if (wp != NULL) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1333 | popup_close_and_callback(wp, &argvars[1]); |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /* |
| 1337 | * popup_hide({id}) |
| 1338 | */ |
| 1339 | void |
| 1340 | f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED) |
| 1341 | { |
| 1342 | int id = (int)tv_get_number(argvars); |
| 1343 | win_T *wp = find_popup_win(id); |
| 1344 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1345 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) == 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1346 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1347 | wp->w_popup_flags |= POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1348 | --wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1349 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1350 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | * popup_show({id}) |
| 1356 | */ |
| 1357 | void |
| 1358 | f_popup_show(typval_T *argvars, typval_T *rettv UNUSED) |
| 1359 | { |
| 1360 | int id = (int)tv_get_number(argvars); |
| 1361 | win_T *wp = find_popup_win(id); |
| 1362 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1363 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) != 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1364 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1365 | wp->w_popup_flags &= ~POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1366 | ++wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1367 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1368 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1369 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1372 | /* |
| 1373 | * popup_settext({id}, {text}) |
| 1374 | */ |
| 1375 | void |
| 1376 | f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED) |
| 1377 | { |
| 1378 | int id = (int)tv_get_number(&argvars[0]); |
| 1379 | win_T *wp = find_popup_win(id); |
| 1380 | |
| 1381 | if (wp != NULL) |
| 1382 | { |
| 1383 | popup_set_buffer_text(wp->w_buffer, argvars[1]); |
| 1384 | popup_adjust_position(wp); |
| 1385 | } |
| 1386 | } |
| 1387 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1388 | static void |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1389 | popup_free(win_T *wp) |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1390 | { |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 1391 | wp->w_buffer->b_locked = FALSE; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1392 | if (wp->w_winrow + wp->w_height >= cmdline_row) |
| 1393 | clear_cmdline = TRUE; |
| 1394 | win_free_popup(wp); |
| 1395 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1396 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1399 | /* |
| 1400 | * Close a popup window by Window-id. |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1401 | * Does not invoke the callback. |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1402 | */ |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1403 | void |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1404 | popup_close(int id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1405 | { |
| 1406 | win_T *wp; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1407 | tabpage_T *tp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1408 | win_T *prev = NULL; |
| 1409 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1410 | // go through global popups |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1411 | for (wp = first_popupwin; wp != NULL; prev = wp, wp = wp->w_next) |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1412 | if (wp->w_id == id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1413 | { |
| 1414 | if (prev == NULL) |
| 1415 | first_popupwin = wp->w_next; |
| 1416 | else |
| 1417 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1418 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1419 | return; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1420 | } |
| 1421 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1422 | // go through tab-local popups |
| 1423 | FOR_ALL_TABPAGES(tp) |
| 1424 | popup_close_tabpage(tp, id); |
| 1425 | } |
| 1426 | |
| 1427 | /* |
| 1428 | * Close a popup window with Window-id "id" in tabpage "tp". |
| 1429 | */ |
| 1430 | void |
| 1431 | popup_close_tabpage(tabpage_T *tp, int id) |
| 1432 | { |
| 1433 | win_T *wp; |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 1434 | win_T **root = &tp->tp_first_popupwin; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1435 | win_T *prev = NULL; |
| 1436 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1437 | for (wp = *root; wp != NULL; prev = wp, wp = wp->w_next) |
| 1438 | if (wp->w_id == id) |
| 1439 | { |
| 1440 | if (prev == NULL) |
| 1441 | *root = wp->w_next; |
| 1442 | else |
| 1443 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1444 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1445 | return; |
| 1446 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | void |
| 1450 | close_all_popups(void) |
| 1451 | { |
| 1452 | while (first_popupwin != NULL) |
| 1453 | popup_close(first_popupwin->w_id); |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 1454 | while (curtab->tp_first_popupwin != NULL) |
| 1455 | popup_close(curtab->tp_first_popupwin->w_id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1456 | } |
| 1457 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1458 | /* |
| 1459 | * popup_move({id}, {options}) |
| 1460 | */ |
| 1461 | void |
| 1462 | f_popup_move(typval_T *argvars, typval_T *rettv UNUSED) |
| 1463 | { |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1464 | dict_T *dict; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1465 | int id = (int)tv_get_number(argvars); |
| 1466 | win_T *wp = find_popup_win(id); |
| 1467 | |
| 1468 | if (wp == NULL) |
| 1469 | return; // invalid {id} |
| 1470 | |
| 1471 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 1472 | { |
| 1473 | emsg(_(e_dictreq)); |
| 1474 | return; |
| 1475 | } |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1476 | dict = argvars[1].vval.v_dict; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1477 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1478 | apply_move_options(wp, dict); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1479 | |
| 1480 | if (wp->w_winrow + wp->w_height >= cmdline_row) |
| 1481 | clear_cmdline = TRUE; |
| 1482 | popup_adjust_position(wp); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1483 | } |
| 1484 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1485 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1486 | * popup_setoptions({id}, {options}) |
| 1487 | */ |
| 1488 | void |
| 1489 | f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) |
| 1490 | { |
| 1491 | dict_T *dict; |
| 1492 | int id = (int)tv_get_number(argvars); |
| 1493 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1494 | linenr_T old_firstline; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1495 | |
| 1496 | if (wp == NULL) |
| 1497 | return; // invalid {id} |
| 1498 | |
| 1499 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 1500 | { |
| 1501 | emsg(_(e_dictreq)); |
| 1502 | return; |
| 1503 | } |
| 1504 | dict = argvars[1].vval.v_dict; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1505 | old_firstline = wp->w_firstline; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1506 | |
| 1507 | apply_move_options(wp, dict); |
| 1508 | apply_general_options(wp, dict); |
| 1509 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1510 | if (old_firstline != wp->w_firstline) |
| 1511 | redraw_win_later(wp, NOT_VALID); |
Bram Moolenaar | ad24a71 | 2019-06-17 20:05:45 +0200 | [diff] [blame] | 1512 | popup_mask_refresh = TRUE; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1513 | popup_adjust_position(wp); |
| 1514 | } |
| 1515 | |
| 1516 | /* |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1517 | * popup_getpos({id}) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1518 | */ |
| 1519 | void |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1520 | f_popup_getpos(typval_T *argvars, typval_T *rettv) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1521 | { |
| 1522 | dict_T *dict; |
| 1523 | int id = (int)tv_get_number(argvars); |
| 1524 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1525 | int top_extra; |
| 1526 | int left_extra; |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1527 | |
| 1528 | if (rettv_dict_alloc(rettv) == OK) |
| 1529 | { |
| 1530 | if (wp == NULL) |
| 1531 | return; // invalid {id} |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1532 | top_extra = popup_top_extra(wp); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1533 | left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 1534 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1535 | dict = rettv->vval.v_dict; |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1536 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1537 | dict_add_number(dict, "line", wp->w_winrow + 1); |
| 1538 | dict_add_number(dict, "col", wp->w_wincol + 1); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1539 | dict_add_number(dict, "width", wp->w_width + left_extra |
| 1540 | + wp->w_popup_border[1] + wp->w_popup_padding[1]); |
| 1541 | dict_add_number(dict, "height", wp->w_height + top_extra |
| 1542 | + wp->w_popup_border[2] + wp->w_popup_padding[2]); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1543 | |
| 1544 | dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra); |
| 1545 | dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra); |
| 1546 | dict_add_number(dict, "core_width", wp->w_width); |
| 1547 | dict_add_number(dict, "core_height", wp->w_height); |
| 1548 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1549 | dict_add_number(dict, "scrollbar", wp->w_has_scrollbar); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1550 | dict_add_number(dict, "visible", |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 1551 | win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1556 | * For popup_getoptions(): add a "border" or "padding" entry to "dict". |
| 1557 | */ |
| 1558 | static void |
| 1559 | get_padding_border(dict_T *dict, int *array, char *name) |
| 1560 | { |
| 1561 | list_T *list; |
| 1562 | int i; |
| 1563 | |
| 1564 | if (array[0] == 0 && array[1] == 0 && array[2] == 0 && array[3] == 0) |
| 1565 | return; |
| 1566 | |
| 1567 | list = list_alloc(); |
| 1568 | if (list != NULL) |
| 1569 | { |
| 1570 | dict_add_list(dict, name, list); |
| 1571 | if (array[0] != 1 || array[1] != 1 || array[2] != 1 || array[3] != 1) |
| 1572 | for (i = 0; i < 4; ++i) |
| 1573 | list_append_number(list, array[i]); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | /* |
| 1578 | * For popup_getoptions(): add a "borderhighlight" entry to "dict". |
| 1579 | */ |
| 1580 | static void |
| 1581 | get_borderhighlight(dict_T *dict, win_T *wp) |
| 1582 | { |
| 1583 | list_T *list; |
| 1584 | int i; |
| 1585 | |
| 1586 | for (i = 0; i < 4; ++i) |
| 1587 | if (wp->w_border_highlight[i] != NULL) |
| 1588 | break; |
| 1589 | if (i == 4) |
| 1590 | return; |
| 1591 | |
| 1592 | list = list_alloc(); |
| 1593 | if (list != NULL) |
| 1594 | { |
| 1595 | dict_add_list(dict, "borderhighlight", list); |
| 1596 | for (i = 0; i < 4; ++i) |
| 1597 | list_append_string(list, wp->w_border_highlight[i], -1); |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | /* |
| 1602 | * For popup_getoptions(): add a "borderchars" entry to "dict". |
| 1603 | */ |
| 1604 | static void |
| 1605 | get_borderchars(dict_T *dict, win_T *wp) |
| 1606 | { |
| 1607 | list_T *list; |
| 1608 | int i; |
| 1609 | char_u buf[NUMBUFLEN]; |
| 1610 | int len; |
| 1611 | |
| 1612 | for (i = 0; i < 8; ++i) |
| 1613 | if (wp->w_border_char[i] != 0) |
| 1614 | break; |
| 1615 | if (i == 8) |
| 1616 | return; |
| 1617 | |
| 1618 | list = list_alloc(); |
| 1619 | if (list != NULL) |
| 1620 | { |
| 1621 | dict_add_list(dict, "borderchars", list); |
| 1622 | for (i = 0; i < 8; ++i) |
| 1623 | { |
| 1624 | len = mb_char2bytes(wp->w_border_char[i], buf); |
| 1625 | list_append_string(list, buf, len); |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | * For popup_getoptions(): add a "moved" entry to "dict". |
| 1632 | */ |
| 1633 | static void |
| 1634 | get_moved_list(dict_T *dict, win_T *wp) |
| 1635 | { |
| 1636 | list_T *list; |
| 1637 | |
| 1638 | list = list_alloc(); |
| 1639 | if (list != NULL) |
| 1640 | { |
| 1641 | dict_add_list(dict, "moved", list); |
| 1642 | list_append_number(list, wp->w_popup_mincol); |
| 1643 | list_append_number(list, wp->w_popup_maxcol); |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | /* |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1648 | * popup_getoptions({id}) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1649 | */ |
| 1650 | void |
| 1651 | f_popup_getoptions(typval_T *argvars, typval_T *rettv) |
| 1652 | { |
| 1653 | dict_T *dict; |
| 1654 | int id = (int)tv_get_number(argvars); |
| 1655 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1656 | tabpage_T *tp; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1657 | int i; |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1658 | |
| 1659 | if (rettv_dict_alloc(rettv) == OK) |
| 1660 | { |
| 1661 | if (wp == NULL) |
| 1662 | return; |
| 1663 | |
| 1664 | dict = rettv->vval.v_dict; |
| 1665 | dict_add_number(dict, "line", wp->w_wantline); |
| 1666 | dict_add_number(dict, "col", wp->w_wantcol); |
| 1667 | dict_add_number(dict, "minwidth", wp->w_minwidth); |
| 1668 | dict_add_number(dict, "minheight", wp->w_minheight); |
| 1669 | dict_add_number(dict, "maxheight", wp->w_maxheight); |
| 1670 | dict_add_number(dict, "maxwidth", wp->w_maxwidth); |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1671 | dict_add_number(dict, "firstline", wp->w_firstline); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1672 | dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1673 | dict_add_number(dict, "zindex", wp->w_zindex); |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1674 | dict_add_number(dict, "fixed", wp->w_popup_fixed); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1675 | dict_add_string(dict, "title", wp->w_popup_title); |
| 1676 | dict_add_number(dict, "wrap", wp->w_p_wrap); |
| 1677 | dict_add_number(dict, "drag", wp->w_popup_drag); |
| 1678 | dict_add_string(dict, "highlight", wp->w_p_wcr); |
| 1679 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1680 | // find the tabpage that holds this popup |
| 1681 | i = 1; |
| 1682 | FOR_ALL_TABPAGES(tp) |
| 1683 | { |
| 1684 | win_T *p; |
| 1685 | |
| 1686 | for (p = tp->tp_first_popupwin; p != NULL; p = wp->w_next) |
| 1687 | if (p->w_id == id) |
| 1688 | break; |
| 1689 | if (p != NULL) |
| 1690 | break; |
| 1691 | ++i; |
| 1692 | } |
| 1693 | if (tp == NULL) |
| 1694 | i = -1; // must be global |
| 1695 | else if (tp == curtab) |
| 1696 | i = 0; |
| 1697 | dict_add_number(dict, "tabpage", i); |
| 1698 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1699 | get_padding_border(dict, wp->w_popup_padding, "padding"); |
| 1700 | get_padding_border(dict, wp->w_popup_border, "border"); |
| 1701 | get_borderhighlight(dict, wp); |
| 1702 | get_borderchars(dict, wp); |
| 1703 | get_moved_list(dict, wp); |
| 1704 | |
| 1705 | if (wp->w_filter_cb.cb_name != NULL) |
| 1706 | dict_add_callback(dict, "filter", &wp->w_filter_cb); |
| 1707 | if (wp->w_close_cb.cb_name != NULL) |
| 1708 | dict_add_callback(dict, "callback", &wp->w_close_cb); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1709 | |
| 1710 | for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); |
| 1711 | ++i) |
| 1712 | if (wp->w_popup_pos == poppos_entries[i].pp_val) |
| 1713 | { |
| 1714 | dict_add_string(dict, "pos", |
| 1715 | (char_u *)poppos_entries[i].pp_name); |
| 1716 | break; |
| 1717 | } |
| 1718 | |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1719 | # if defined(FEAT_TIMERS) |
| 1720 | dict_add_number(dict, "time", wp->w_popup_timer != NULL |
| 1721 | ? (long)wp->w_popup_timer->tr_interval : 0L); |
| 1722 | # endif |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1723 | } |
| 1724 | } |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 1725 | |
| 1726 | int |
Bram Moolenaar | 8cdbd5b | 2019-06-16 15:50:45 +0200 | [diff] [blame] | 1727 | error_if_popup_window() |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 1728 | { |
| 1729 | if (bt_popup(curwin->w_buffer)) |
| 1730 | { |
| 1731 | emsg(_("E994: Not allowed in a popup window")); |
| 1732 | return TRUE; |
| 1733 | } |
| 1734 | return FALSE; |
| 1735 | } |
| 1736 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1737 | /* |
| 1738 | * Reset all the POPF_HANDLED flags in global popup windows and popup windows |
Bram Moolenaar | fc06cbb | 2019-06-15 14:14:31 +0200 | [diff] [blame] | 1739 | * in the current tab page. |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1740 | */ |
| 1741 | void |
| 1742 | popup_reset_handled() |
| 1743 | { |
| 1744 | win_T *wp; |
| 1745 | |
| 1746 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1747 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 1748 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 1749 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | * Find the next visible popup where POPF_HANDLED is not set. |
| 1754 | * Must have called popup_reset_handled() first. |
| 1755 | * When "lowest" is TRUE find the popup with the lowest zindex, otherwise the |
| 1756 | * popup with the highest zindex. |
| 1757 | */ |
| 1758 | win_T * |
| 1759 | find_next_popup(int lowest) |
| 1760 | { |
| 1761 | win_T *wp; |
| 1762 | win_T *found_wp; |
| 1763 | int found_zindex; |
| 1764 | |
| 1765 | found_zindex = lowest ? INT_MAX : 0; |
| 1766 | found_wp = NULL; |
| 1767 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1768 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 1769 | && (lowest ? wp->w_zindex < found_zindex |
| 1770 | : wp->w_zindex > found_zindex)) |
| 1771 | { |
| 1772 | found_zindex = wp->w_zindex; |
| 1773 | found_wp = wp; |
| 1774 | } |
| 1775 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 1776 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 1777 | && (lowest ? wp->w_zindex < found_zindex |
| 1778 | : wp->w_zindex > found_zindex)) |
| 1779 | { |
| 1780 | found_zindex = wp->w_zindex; |
| 1781 | found_wp = wp; |
| 1782 | } |
| 1783 | |
| 1784 | if (found_wp != NULL) |
| 1785 | found_wp->w_popup_flags |= POPF_HANDLED; |
| 1786 | return found_wp; |
| 1787 | } |
| 1788 | |
| 1789 | /* |
| 1790 | * Invoke the filter callback for window "wp" with typed character "c". |
| 1791 | * Uses the global "mod_mask" for modifiers. |
| 1792 | * Returns the return value of the filter. |
| 1793 | * Careful: The filter may make "wp" invalid! |
| 1794 | */ |
| 1795 | static int |
| 1796 | invoke_popup_filter(win_T *wp, int c) |
| 1797 | { |
| 1798 | int res; |
| 1799 | typval_T rettv; |
| 1800 | int dummy; |
| 1801 | typval_T argv[3]; |
| 1802 | char_u buf[NUMBUFLEN]; |
| 1803 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1804 | // Emergency exit: CTRL-C closes the popup. |
| 1805 | if (c == Ctrl_C) |
| 1806 | { |
| 1807 | rettv.v_type = VAR_NUMBER; |
| 1808 | rettv.vval.v_number = -1; |
| 1809 | popup_close_and_callback(wp, &rettv); |
| 1810 | return 1; |
| 1811 | } |
| 1812 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1813 | argv[0].v_type = VAR_NUMBER; |
| 1814 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 1815 | |
| 1816 | // Convert the number to a string, so that the function can use: |
| 1817 | // if a:c == "\<F2>" |
| 1818 | buf[special_to_buf(c, mod_mask, TRUE, buf)] = NUL; |
| 1819 | argv[1].v_type = VAR_STRING; |
| 1820 | argv[1].vval.v_string = vim_strsave(buf); |
| 1821 | |
| 1822 | argv[2].v_type = VAR_UNKNOWN; |
| 1823 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1824 | // NOTE: The callback might close the popup, thus make "wp" invalid. |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1825 | call_callback(&wp->w_filter_cb, -1, |
| 1826 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
| 1827 | res = tv_get_number(&rettv); |
| 1828 | vim_free(argv[1].vval.v_string); |
| 1829 | clear_tv(&rettv); |
| 1830 | return res; |
| 1831 | } |
| 1832 | |
| 1833 | /* |
| 1834 | * Called when "c" was typed: invoke popup filter callbacks. |
| 1835 | * Returns TRUE when the character was consumed, |
| 1836 | */ |
| 1837 | int |
| 1838 | popup_do_filter(int c) |
| 1839 | { |
| 1840 | int res = FALSE; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1841 | win_T *wp; |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1842 | |
| 1843 | popup_reset_handled(); |
| 1844 | |
| 1845 | while (!res && (wp = find_next_popup(FALSE)) != NULL) |
| 1846 | if (wp->w_filter_cb.cb_name != NULL) |
| 1847 | res = invoke_popup_filter(wp, c); |
| 1848 | |
| 1849 | return res; |
| 1850 | } |
| 1851 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1852 | /* |
| 1853 | * Called when the cursor moved: check if any popup needs to be closed if the |
| 1854 | * cursor moved far enough. |
| 1855 | */ |
| 1856 | void |
| 1857 | popup_check_cursor_pos() |
| 1858 | { |
| 1859 | win_T *wp; |
| 1860 | typval_T tv; |
| 1861 | |
| 1862 | popup_reset_handled(); |
| 1863 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 1864 | if (wp->w_popup_curwin != NULL |
| 1865 | && (curwin != wp->w_popup_curwin |
| 1866 | || curwin->w_cursor.lnum != wp->w_popup_lnum |
| 1867 | || curwin->w_cursor.col < wp->w_popup_mincol |
| 1868 | || curwin->w_cursor.col > wp->w_popup_maxcol)) |
| 1869 | { |
| 1870 | tv.v_type = VAR_NUMBER; |
| 1871 | tv.vval.v_number = -1; |
| 1872 | popup_close_and_callback(wp, &tv); |
| 1873 | } |
| 1874 | } |
| 1875 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 1876 | /* |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 1877 | * Return TRUE if "col" / "line" matches with an entry in w_popup_mask. |
| 1878 | * "col" and "line" are screen coordinates. |
| 1879 | */ |
| 1880 | static int |
| 1881 | popup_masked(win_T *wp, int screencol, int screenline) |
| 1882 | { |
| 1883 | int col = screencol - wp->w_wincol + 1; |
| 1884 | int line = screenline - wp->w_winrow + 1; |
| 1885 | listitem_T *lio, *li; |
| 1886 | int width, height; |
| 1887 | |
| 1888 | if (wp->w_popup_mask == NULL) |
| 1889 | return FALSE; |
| 1890 | width = popup_width(wp); |
| 1891 | height = popup_height(wp); |
| 1892 | |
| 1893 | for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next) |
| 1894 | { |
| 1895 | int cols, cole; |
| 1896 | int lines, linee; |
| 1897 | |
| 1898 | li = lio->li_tv.vval.v_list->lv_first; |
| 1899 | cols = tv_get_number(&li->li_tv); |
| 1900 | if (cols < 0) |
| 1901 | cols = width + cols + 1; |
| 1902 | if (col < cols) |
| 1903 | continue; |
| 1904 | li = li->li_next; |
| 1905 | cole = tv_get_number(&li->li_tv); |
| 1906 | if (cole < 0) |
| 1907 | cole = width + cole + 1; |
| 1908 | if (col > cole) |
| 1909 | continue; |
| 1910 | li = li->li_next; |
| 1911 | lines = tv_get_number(&li->li_tv); |
| 1912 | if (lines < 0) |
| 1913 | lines = height + lines + 1; |
| 1914 | if (line < lines) |
| 1915 | continue; |
| 1916 | li = li->li_next; |
| 1917 | linee = tv_get_number(&li->li_tv); |
| 1918 | if (linee < 0) |
| 1919 | linee = height + linee + 1; |
| 1920 | if (line > linee) |
| 1921 | continue; |
| 1922 | return TRUE; |
| 1923 | } |
| 1924 | return FALSE; |
| 1925 | } |
| 1926 | |
| 1927 | /* |
| 1928 | * Set flags in popup_transparent[] for window "wp" to "val". |
| 1929 | */ |
| 1930 | static void |
| 1931 | update_popup_transparent(win_T *wp, int val) |
| 1932 | { |
| 1933 | if (wp->w_popup_mask != NULL) |
| 1934 | { |
| 1935 | int width = popup_width(wp); |
| 1936 | int height = popup_height(wp); |
| 1937 | listitem_T *lio, *li; |
| 1938 | int cols, cole; |
| 1939 | int lines, linee; |
| 1940 | int col, line; |
| 1941 | |
| 1942 | for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next) |
| 1943 | { |
| 1944 | li = lio->li_tv.vval.v_list->lv_first; |
| 1945 | cols = tv_get_number(&li->li_tv); |
| 1946 | if (cols < 0) |
| 1947 | cols = width + cols + 1; |
| 1948 | li = li->li_next; |
| 1949 | cole = tv_get_number(&li->li_tv); |
| 1950 | if (cole < 0) |
| 1951 | cole = width + cole + 1; |
| 1952 | li = li->li_next; |
| 1953 | lines = tv_get_number(&li->li_tv); |
| 1954 | if (lines < 0) |
| 1955 | lines = height + lines + 1; |
| 1956 | li = li->li_next; |
| 1957 | linee = tv_get_number(&li->li_tv); |
| 1958 | if (linee < 0) |
| 1959 | linee = height + linee + 1; |
| 1960 | |
| 1961 | --cols; |
| 1962 | --lines; |
| 1963 | for (line = lines; line < linee && line < screen_Rows; ++line) |
| 1964 | for (col = cols; col < cole && col < screen_Columns; ++col) |
| 1965 | popup_transparent[(line + wp->w_winrow) * screen_Columns |
| 1966 | + col + wp->w_wincol] = val; |
| 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | /* |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 1972 | * Update "popup_mask" if needed. |
| 1973 | * Also recomputes the popup size and positions. |
| 1974 | * Also updates "popup_visible". |
| 1975 | * Also marks window lines for redrawing. |
| 1976 | */ |
| 1977 | void |
| 1978 | may_update_popup_mask(int type) |
| 1979 | { |
| 1980 | win_T *wp; |
| 1981 | short *mask; |
| 1982 | int line, col; |
| 1983 | int redraw_all = FALSE; |
| 1984 | |
| 1985 | // Need to recompute when switching tabs. |
| 1986 | // Also recompute when the type is CLEAR or NOT_VALID, something basic |
| 1987 | // (such as the screen size) must have changed. |
| 1988 | if (popup_mask_tab != curtab || type >= NOT_VALID) |
| 1989 | { |
| 1990 | popup_mask_refresh = TRUE; |
| 1991 | redraw_all = TRUE; |
| 1992 | } |
| 1993 | if (!popup_mask_refresh) |
| 1994 | { |
| 1995 | // Check if any buffer has changed. |
| 1996 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1997 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 1998 | popup_mask_refresh = TRUE; |
| 1999 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 2000 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2001 | popup_mask_refresh = TRUE; |
| 2002 | if (!popup_mask_refresh) |
| 2003 | return; |
| 2004 | } |
| 2005 | |
| 2006 | // Need to update the mask, something has changed. |
| 2007 | popup_mask_refresh = FALSE; |
| 2008 | popup_mask_tab = curtab; |
| 2009 | popup_visible = FALSE; |
| 2010 | |
| 2011 | // If redrawing everything, just update "popup_mask". |
| 2012 | // If redrawing only what is needed, update "popup_mask_next" and then |
| 2013 | // compare with "popup_mask" to see what changed. |
| 2014 | if (type >= SOME_VALID) |
| 2015 | mask = popup_mask; |
| 2016 | else |
| 2017 | mask = popup_mask_next; |
| 2018 | vim_memset(mask, 0, screen_Rows * screen_Columns * sizeof(short)); |
| 2019 | |
| 2020 | // Find the window with the lowest zindex that hasn't been handled yet, |
| 2021 | // so that the window with a higher zindex overwrites the value in |
| 2022 | // popup_mask. |
| 2023 | popup_reset_handled(); |
| 2024 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 2025 | { |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2026 | int height = popup_height(wp); |
| 2027 | int width = popup_width(wp); |
| 2028 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2029 | popup_visible = TRUE; |
| 2030 | |
| 2031 | // Recompute the position if the text changed. |
| 2032 | if (redraw_all |
| 2033 | || wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2034 | popup_adjust_position(wp); |
| 2035 | |
| 2036 | for (line = wp->w_winrow; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2037 | line < wp->w_winrow + height && line < screen_Rows; ++line) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2038 | for (col = wp->w_wincol; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2039 | col < wp->w_wincol + width && col < screen_Columns; ++col) |
| 2040 | if (!popup_masked(wp, col, line)) |
| 2041 | mask[line * screen_Columns + col] = wp->w_zindex; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | // Only check which lines are to be updated if not already |
| 2045 | // updating all lines. |
| 2046 | if (mask == popup_mask_next) |
| 2047 | for (line = 0; line < screen_Rows; ++line) |
| 2048 | { |
| 2049 | int col_done = 0; |
| 2050 | |
| 2051 | for (col = 0; col < screen_Columns; ++col) |
| 2052 | { |
| 2053 | int off = line * screen_Columns + col; |
| 2054 | |
| 2055 | if (popup_mask[off] != popup_mask_next[off]) |
| 2056 | { |
| 2057 | popup_mask[off] = popup_mask_next[off]; |
| 2058 | |
| 2059 | if (line >= cmdline_row) |
| 2060 | { |
| 2061 | // the command line needs to be cleared if text below |
| 2062 | // the popup is now visible. |
| 2063 | if (!msg_scrolled && popup_mask_next[off] == 0) |
| 2064 | clear_cmdline = TRUE; |
| 2065 | } |
| 2066 | else if (col >= col_done) |
| 2067 | { |
| 2068 | linenr_T lnum; |
| 2069 | int line_cp = line; |
| 2070 | int col_cp = col; |
| 2071 | |
| 2072 | // The screen position "line" / "col" needs to be |
| 2073 | // redrawn. Figure out what window that is and update |
| 2074 | // w_redraw_top and w_redr_bot. Only needs to be done |
| 2075 | // once for each window line. |
| 2076 | wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP); |
| 2077 | if (wp != NULL) |
| 2078 | { |
| 2079 | if (line_cp >= wp->w_height) |
| 2080 | // In (or below) status line |
| 2081 | wp->w_redr_status = TRUE; |
| 2082 | // compute the position in the buffer line from the |
| 2083 | // position on the screen |
| 2084 | else if (mouse_comp_pos(wp, &line_cp, &col_cp, |
| 2085 | &lnum)) |
| 2086 | // past bottom |
| 2087 | wp->w_redr_status = TRUE; |
| 2088 | else |
| 2089 | redrawWinline(wp, lnum); |
| 2090 | |
| 2091 | // This line is going to be redrawn, no need to |
| 2092 | // check until the right side of the window. |
| 2093 | col_done = wp->w_wincol + wp->w_width - 1; |
| 2094 | } |
| 2095 | } |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | /* |
| 2102 | * Return a string of "len" spaces in IObuff. |
| 2103 | */ |
| 2104 | static char_u * |
| 2105 | get_spaces(int len) |
| 2106 | { |
| 2107 | vim_memset(IObuff, ' ', (size_t)len); |
| 2108 | IObuff[len] = NUL; |
| 2109 | return IObuff; |
| 2110 | } |
| 2111 | |
| 2112 | /* |
| 2113 | * Update popup windows. They are drawn on top of normal windows. |
| 2114 | * "win_update" is called for each popup window, lowest zindex first. |
| 2115 | */ |
| 2116 | void |
| 2117 | update_popups(void (*win_update)(win_T *wp)) |
| 2118 | { |
| 2119 | win_T *wp; |
| 2120 | int top_off; |
| 2121 | int left_off; |
| 2122 | int total_width; |
| 2123 | int total_height; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2124 | int top_padding; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2125 | int popup_attr; |
| 2126 | int border_attr[4]; |
| 2127 | int border_char[8]; |
| 2128 | char_u buf[MB_MAXBYTES]; |
| 2129 | int row; |
| 2130 | int i; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2131 | int sb_thumb_top; |
| 2132 | int sb_thumb_height; |
| 2133 | int attr_scroll = highlight_attr[HLF_PSB]; |
| 2134 | int attr_thumb = highlight_attr[HLF_PST]; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2135 | |
| 2136 | // Find the window with the lowest zindex that hasn't been updated yet, |
| 2137 | // so that the window with a higher zindex is drawn later, thus goes on |
| 2138 | // top. |
| 2139 | popup_reset_handled(); |
| 2140 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 2141 | { |
| 2142 | // This drawing uses the zindex of the popup window, so that it's on |
| 2143 | // top of the text but doesn't draw when another popup with higher |
| 2144 | // zindex is on top of the character. |
| 2145 | screen_zindex = wp->w_zindex; |
| 2146 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2147 | // Set flags in popup_transparent[] for masked cells. |
| 2148 | update_popup_transparent(wp, 1); |
| 2149 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2150 | // adjust w_winrow and w_wincol for border and padding, since |
| 2151 | // win_update() doesn't handle them. |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2152 | top_off = popup_top_extra(wp); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2153 | left_off = wp->w_popup_padding[3] + wp->w_popup_border[3]; |
| 2154 | wp->w_winrow += top_off; |
| 2155 | wp->w_wincol += left_off; |
| 2156 | |
| 2157 | // Draw the popup text. |
| 2158 | win_update(wp); |
| 2159 | |
| 2160 | wp->w_winrow -= top_off; |
| 2161 | wp->w_wincol -= left_off; |
| 2162 | |
| 2163 | total_width = wp->w_popup_border[3] + wp->w_popup_padding[3] |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2164 | + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1] |
| 2165 | + wp->w_has_scrollbar; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2166 | total_height = popup_top_extra(wp) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2167 | + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
| 2168 | popup_attr = get_wcr_attr(wp); |
| 2169 | |
| 2170 | // We can only use these line drawing characters when 'encoding' is |
| 2171 | // "utf-8" and 'ambiwidth' is "single". |
| 2172 | if (enc_utf8 && *p_ambw == 's') |
| 2173 | { |
| 2174 | border_char[0] = border_char[2] = 0x2550; |
| 2175 | border_char[1] = border_char[3] = 0x2551; |
| 2176 | border_char[4] = 0x2554; |
| 2177 | border_char[5] = 0x2557; |
| 2178 | border_char[6] = 0x255d; |
| 2179 | border_char[7] = 0x255a; |
| 2180 | } |
| 2181 | else |
| 2182 | { |
| 2183 | border_char[0] = border_char[2] = '-'; |
| 2184 | border_char[1] = border_char[3] = '|'; |
| 2185 | for (i = 4; i < 8; ++i) |
| 2186 | border_char[i] = '+'; |
| 2187 | } |
| 2188 | for (i = 0; i < 8; ++i) |
| 2189 | if (wp->w_border_char[i] != 0) |
| 2190 | border_char[i] = wp->w_border_char[i]; |
| 2191 | |
| 2192 | for (i = 0; i < 4; ++i) |
| 2193 | { |
| 2194 | border_attr[i] = popup_attr; |
| 2195 | if (wp->w_border_highlight[i] != NULL) |
| 2196 | border_attr[i] = syn_name2attr(wp->w_border_highlight[i]); |
| 2197 | } |
| 2198 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2199 | top_padding = wp->w_popup_padding[0]; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2200 | if (wp->w_popup_border[0] > 0) |
| 2201 | { |
| 2202 | // top border |
| 2203 | screen_fill(wp->w_winrow, wp->w_winrow + 1, |
| 2204 | wp->w_wincol, |
| 2205 | wp->w_wincol + total_width, |
| 2206 | wp->w_popup_border[3] != 0 |
| 2207 | ? border_char[4] : border_char[0], |
| 2208 | border_char[0], border_attr[0]); |
| 2209 | if (wp->w_popup_border[1] > 0) |
| 2210 | { |
| 2211 | buf[mb_char2bytes(border_char[5], buf)] = NUL; |
| 2212 | screen_puts(buf, wp->w_winrow, |
| 2213 | wp->w_wincol + total_width - 1, border_attr[1]); |
| 2214 | } |
| 2215 | } |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2216 | else if (wp->w_popup_padding[0] == 0 && popup_top_extra(wp) > 0) |
| 2217 | top_padding = 1; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2218 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2219 | if (top_padding > 0) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2220 | { |
| 2221 | // top padding |
| 2222 | row = wp->w_winrow + wp->w_popup_border[0]; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2223 | screen_fill(row, row + top_padding, |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2224 | wp->w_wincol + wp->w_popup_border[3], |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2225 | wp->w_wincol + total_width - wp->w_popup_border[1] |
| 2226 | - wp->w_has_scrollbar, |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2227 | ' ', ' ', popup_attr); |
| 2228 | } |
| 2229 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2230 | // Title goes on top of border or padding. |
| 2231 | if (wp->w_popup_title != NULL) |
| 2232 | screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1, |
| 2233 | wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr); |
| 2234 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2235 | // Compute scrollbar thumb position and size. |
| 2236 | if (wp->w_has_scrollbar) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2237 | { |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2238 | linenr_T linecount = wp->w_buffer->b_ml.ml_line_count; |
| 2239 | |
| 2240 | sb_thumb_height = wp->w_height * wp->w_height / linecount; |
| 2241 | if (sb_thumb_height == 0) |
| 2242 | sb_thumb_height = 1; |
| 2243 | sb_thumb_top = ((wp->w_topline * (wp->w_height - sb_thumb_height) |
| 2244 | + (linecount - wp->w_height) / 2)) |
| 2245 | / (linecount - (wp->w_height - sb_thumb_height)); |
| 2246 | } |
| 2247 | |
| 2248 | for (i = wp->w_popup_border[0]; |
| 2249 | i < total_height - wp->w_popup_border[2]; ++i) |
| 2250 | { |
| 2251 | row = wp->w_winrow + i; |
| 2252 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2253 | // left border |
| 2254 | if (wp->w_popup_border[3] > 0) |
| 2255 | { |
| 2256 | buf[mb_char2bytes(border_char[3], buf)] = NUL; |
| 2257 | screen_puts(buf, row, wp->w_wincol, border_attr[3]); |
| 2258 | } |
| 2259 | // left padding |
| 2260 | if (wp->w_popup_padding[3] > 0) |
| 2261 | screen_puts(get_spaces(wp->w_popup_padding[3]), row, |
| 2262 | wp->w_wincol + wp->w_popup_border[3], popup_attr); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2263 | // scrollbar |
| 2264 | if (wp->w_has_scrollbar) |
| 2265 | { |
| 2266 | int line = i - top_off; |
| 2267 | int scroll_col = wp->w_wincol + total_width - 1 |
| 2268 | - wp->w_popup_border[1]; |
| 2269 | |
| 2270 | if (line >= 0 && line < wp->w_height) |
| 2271 | screen_putchar(' ', row, scroll_col, |
| 2272 | line >= sb_thumb_top |
| 2273 | && line < sb_thumb_top + sb_thumb_height |
| 2274 | ? attr_thumb : attr_scroll); |
| 2275 | else |
| 2276 | screen_putchar(' ', row, scroll_col, popup_attr); |
| 2277 | } |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2278 | // right border |
| 2279 | if (wp->w_popup_border[1] > 0) |
| 2280 | { |
| 2281 | buf[mb_char2bytes(border_char[1], buf)] = NUL; |
| 2282 | screen_puts(buf, row, |
| 2283 | wp->w_wincol + total_width - 1, border_attr[1]); |
| 2284 | } |
| 2285 | // right padding |
| 2286 | if (wp->w_popup_padding[1] > 0) |
| 2287 | screen_puts(get_spaces(wp->w_popup_padding[1]), row, |
| 2288 | wp->w_wincol + wp->w_popup_border[3] |
| 2289 | + wp->w_popup_padding[3] + wp->w_width, popup_attr); |
| 2290 | } |
| 2291 | |
| 2292 | if (wp->w_popup_padding[2] > 0) |
| 2293 | { |
| 2294 | // bottom padding |
| 2295 | row = wp->w_winrow + wp->w_popup_border[0] |
| 2296 | + wp->w_popup_padding[0] + wp->w_height; |
| 2297 | screen_fill(row, row + wp->w_popup_padding[2], |
| 2298 | wp->w_wincol + wp->w_popup_border[3], |
| 2299 | wp->w_wincol + total_width - wp->w_popup_border[1], |
| 2300 | ' ', ' ', popup_attr); |
| 2301 | } |
| 2302 | |
| 2303 | if (wp->w_popup_border[2] > 0) |
| 2304 | { |
| 2305 | // bottom border |
| 2306 | row = wp->w_winrow + total_height - 1; |
| 2307 | screen_fill(row , row + 1, |
| 2308 | wp->w_wincol, |
| 2309 | wp->w_wincol + total_width, |
| 2310 | wp->w_popup_border[3] != 0 |
| 2311 | ? border_char[7] : border_char[2], |
| 2312 | border_char[2], border_attr[2]); |
| 2313 | if (wp->w_popup_border[1] > 0) |
| 2314 | { |
| 2315 | buf[mb_char2bytes(border_char[6], buf)] = NUL; |
| 2316 | screen_puts(buf, row, |
| 2317 | wp->w_wincol + total_width - 1, border_attr[2]); |
| 2318 | } |
| 2319 | } |
| 2320 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2321 | update_popup_transparent(wp, 0); |
| 2322 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2323 | // Back to the normal zindex. |
| 2324 | screen_zindex = 0; |
| 2325 | } |
| 2326 | } |
| 2327 | |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 2328 | /* |
| 2329 | * Mark references in callbacks of one popup window. |
| 2330 | */ |
| 2331 | static int |
| 2332 | set_ref_in_one_popup(win_T *wp, int copyID) |
| 2333 | { |
| 2334 | int abort = FALSE; |
| 2335 | typval_T tv; |
| 2336 | |
| 2337 | if (wp->w_close_cb.cb_partial != NULL) |
| 2338 | { |
| 2339 | tv.v_type = VAR_PARTIAL; |
| 2340 | tv.vval.v_partial = wp->w_close_cb.cb_partial; |
| 2341 | abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
| 2342 | } |
| 2343 | if (wp->w_filter_cb.cb_partial != NULL) |
| 2344 | { |
| 2345 | tv.v_type = VAR_PARTIAL; |
| 2346 | tv.vval.v_partial = wp->w_filter_cb.cb_partial; |
| 2347 | abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
| 2348 | } |
Bram Moolenaar | 7be3ab2 | 2019-06-23 01:46:15 +0200 | [diff] [blame] | 2349 | abort = abort || set_ref_in_list(wp->w_popup_mask, copyID); |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 2350 | return abort; |
| 2351 | } |
| 2352 | |
| 2353 | /* |
| 2354 | * Set reference in callbacks of popup windows. |
| 2355 | */ |
| 2356 | int |
| 2357 | set_ref_in_popups(int copyID) |
| 2358 | { |
| 2359 | int abort = FALSE; |
| 2360 | win_T *wp; |
| 2361 | tabpage_T *tp; |
| 2362 | |
| 2363 | for (wp = first_popupwin; !abort && wp != NULL; wp = wp->w_next) |
| 2364 | abort = abort || set_ref_in_one_popup(wp, copyID); |
| 2365 | |
| 2366 | FOR_ALL_TABPAGES(tp) |
| 2367 | { |
| 2368 | for (wp = tp->tp_first_popupwin; !abort && wp != NULL; wp = wp->w_next) |
| 2369 | abort = abort || set_ref_in_one_popup(wp, copyID); |
| 2370 | if (abort) |
| 2371 | break; |
| 2372 | } |
| 2373 | return abort; |
| 2374 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2375 | #endif // FEAT_TEXT_PROP |