comparison src/popupwin.c @ 31778:579c846086eb v9.0.1221

patch 9.0.1221: code is indented more than necessary Commit: https://github.com/vim/vim/commit/f97a295ccaa9803367f3714cdefce4e2283c771d Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Jan 18 18:17:48 2023 +0000 patch 9.0.1221: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11833)
author Bram Moolenaar <Bram@vim.org>
date Wed, 18 Jan 2023 19:30:03 +0100
parents b6bef244837e
children 4545f58c8490
comparison
equal deleted inserted replaced
31777:84bb462086cf 31778:579c846086eb
96 set_padding_border(dict_T *dict, int *array, char *name, int max_val) 96 set_padding_border(dict_T *dict, int *array, char *name, int max_val)
97 { 97 {
98 dictitem_T *di; 98 dictitem_T *di;
99 99
100 di = dict_find(dict, (char_u *)name, -1); 100 di = dict_find(dict, (char_u *)name, -1);
101 if (di != NULL) 101 if (di == NULL)
102 { 102 return;
103 if (di->di_tv.v_type != VAR_LIST) 103
104 emsg(_(e_list_required)); 104 if (di->di_tv.v_type != VAR_LIST)
105 else 105 {
106 { 106 emsg(_(e_list_required));
107 list_T *list = di->di_tv.vval.v_list; 107 return;
108 listitem_T *li; 108 }
109 int i; 109
110 int nr; 110 list_T *list = di->di_tv.vval.v_list;
111 111 listitem_T *li;
112 for (i = 0; i < 4; ++i) 112 int i;
113 array[i] = 1; 113 int nr;
114 if (list != NULL) 114
115 { 115 for (i = 0; i < 4; ++i)
116 CHECK_LIST_MATERIALIZE(list); 116 array[i] = 1;
117 for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; 117 if (list == NULL)
118 ++i, li = li->li_next) 118 return;
119 { 119
120 nr = (int)tv_get_number(&li->li_tv); 120 CHECK_LIST_MATERIALIZE(list);
121 if (nr >= 0) 121 for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len;
122 array[i] = nr > max_val ? max_val : nr; 122 ++i, li = li->li_next)
123 } 123 {
124 } 124 nr = (int)tv_get_number(&li->li_tv);
125 } 125 if (nr >= 0)
126 array[i] = nr > max_val ? max_val : nr;
126 } 127 }
127 } 128 }
128 129
129 /* 130 /*
130 * Used when popup options contain "moved": set default moved values. 131 * Used when popup options contain "moved": set default moved values.
145 set_moved_columns(win_T *wp, int flags) 146 set_moved_columns(win_T *wp, int flags)
146 { 147 {
147 char_u *ptr; 148 char_u *ptr;
148 int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR); 149 int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR);
149 150
150 if (len > 0) 151 if (len <= 0)
151 { 152 return;
152 wp->w_popup_mincol = (int)(ptr - ml_get_curline()); 153
153 wp->w_popup_maxcol = wp->w_popup_mincol + len - 1; 154 wp->w_popup_mincol = (int)(ptr - ml_get_curline());
154 } 155 wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
155 } 156 }
156 157
157 /* 158 /*
158 * Used when popup options contain "mousemoved": set default moved values. 159 * Used when popup options contain "mousemoved": set default moved values.
159 */ 160 */
167 168
168 static void 169 static void
169 update_popup_uses_mouse_move(void) 170 update_popup_uses_mouse_move(void)
170 { 171 {
171 popup_uses_mouse_move = FALSE; 172 popup_uses_mouse_move = FALSE;
172 if (popup_visible) 173 if (!popup_visible)
173 { 174 return;
174 win_T *wp; 175
175 176 win_T *wp;
176 FOR_ALL_POPUPWINS(wp) 177
177 if (wp->w_popup_mouse_row != 0) 178 FOR_ALL_POPUPWINS(wp)
178 { 179 if (wp->w_popup_mouse_row != 0)
179 popup_uses_mouse_move = TRUE; 180 {
180 return; 181 popup_uses_mouse_move = TRUE;
181 } 182 return;
182 FOR_ALL_POPUPWINS_IN_TAB(curtab, wp) 183 }
183 if (wp->w_popup_mouse_row != 0) 184 FOR_ALL_POPUPWINS_IN_TAB(curtab, wp)
184 { 185 if (wp->w_popup_mouse_row != 0)
185 popup_uses_mouse_move = TRUE; 186 {
186 return; 187 popup_uses_mouse_move = TRUE;
187 } 188 return;
188 } 189 }
189 } 190 }
190 191
191 /* 192 /*
192 * Used when popup options contain "moved" with "word" or "WORD". 193 * Used when popup options contain "moved" with "word" or "WORD".
193 */ 194 */
199 int col; 200 int col;
200 pos_T pos; 201 pos_T pos;
201 colnr_T mcol; 202 colnr_T mcol;
202 203
203 if (find_word_under_cursor(mouse_row, mouse_col, TRUE, flags, 204 if (find_word_under_cursor(mouse_row, mouse_col, TRUE, flags,
204 &textwp, &pos.lnum, &text, NULL, &col) == OK) 205 &textwp, &pos.lnum, &text, NULL, &col) != OK)
205 { 206 return;
206 // convert text column to mouse column 207
207 pos.col = col; 208 // convert text column to mouse column
208 pos.coladd = 0; 209 pos.col = col;
209 getvcol(textwp, &pos, &mcol, NULL, NULL); 210 pos.coladd = 0;
210 wp->w_popup_mouse_mincol = mcol; 211 getvcol(textwp, &pos, &mcol, NULL, NULL);
211 212 wp->w_popup_mouse_mincol = mcol;
212 pos.col = col + (colnr_T)STRLEN(text) - 1; 213
213 getvcol(textwp, &pos, NULL, NULL, &mcol); 214 pos.col = col + (colnr_T)STRLEN(text) - 1;
214 wp->w_popup_mouse_maxcol = mcol; 215 getvcol(textwp, &pos, NULL, NULL, &mcol);
215 vim_free(text); 216 wp->w_popup_mouse_maxcol = mcol;
216 } 217 vim_free(text);
217 } 218 }
218 219
219 /* 220 /*
220 * Return TRUE if "row"/"col" is on the border of the popup. 221 * Return TRUE if "row"/"col" is on the border of the popup.
221 * The values are relative to the top-left corner. 222 * The values are relative to the top-left corner.
388 * Handle a click in a popup window, if it is in the scrollbar. 389 * Handle a click in a popup window, if it is in the scrollbar.
389 */ 390 */
390 void 391 void
391 popup_handle_scrollbar_click(win_T *wp, int row, int col) 392 popup_handle_scrollbar_click(win_T *wp, int row, int col)
392 { 393 {
393 if (popup_is_in_scrollbar(wp, row, col)) 394 if (!popup_is_in_scrollbar(wp, row, col))
394 { 395 return;
395 int height = popup_height(wp); 396
396 int new_topline = wp->w_topline; 397 int height = popup_height(wp);
397 398 int new_topline = wp->w_topline;
398 if (row >= height / 2) 399
399 { 400 if (row >= height / 2)
400 // Click in lower half, scroll down. 401 {
401 if (wp->w_topline < wp->w_buffer->b_ml.ml_line_count) 402 // Click in lower half, scroll down.
402 ++new_topline; 403 if (wp->w_topline < wp->w_buffer->b_ml.ml_line_count)
403 } 404 ++new_topline;
404 else if (wp->w_topline > 1) 405 }
405 // click on upper half, scroll up. 406 else if (wp->w_topline > 1)
406 --new_topline; 407 // click on upper half, scroll up.
407 if (new_topline != wp->w_topline) 408 --new_topline;
408 { 409
409 set_topline(wp, new_topline); 410 if (new_topline == wp->w_topline)
410 if (wp == curwin) 411 return;
411 { 412
412 if (wp->w_cursor.lnum < wp->w_topline) 413 set_topline(wp, new_topline);
413 { 414 if (wp == curwin)
414 wp->w_cursor.lnum = wp->w_topline; 415 {
415 check_cursor(); 416 if (wp->w_cursor.lnum < wp->w_topline)
416 } 417 {
417 else if (wp->w_cursor.lnum >= wp->w_botline) 418 wp->w_cursor.lnum = wp->w_topline;
418 { 419 check_cursor();
419 wp->w_cursor.lnum = wp->w_botline - 1; 420 }
420 check_cursor(); 421 else if (wp->w_cursor.lnum >= wp->w_botline)
421 } 422 {
422 } 423 wp->w_cursor.lnum = wp->w_botline - 1;
423 popup_set_firstline(wp); 424 check_cursor();
424 redraw_win_later(wp, UPD_NOT_VALID); 425 }
425 } 426 }
426 } 427 popup_set_firstline(wp);
428 redraw_win_later(wp, UPD_NOT_VALID);
427 } 429 }
428 430
429 #if defined(FEAT_TIMERS) 431 #if defined(FEAT_TIMERS)
430 /* 432 /*
431 * Add a timer to "wp" with "time". 433 * Add a timer to "wp" with "time".
439 typval_T tv; 441 typval_T tv;
440 442
441 vim_snprintf((char *)cbbuf, sizeof(cbbuf), 443 vim_snprintf((char *)cbbuf, sizeof(cbbuf),
442 close ? "(_) => popup_close(%d)" : "(_) => popup_hide(%d)", 444 close ? "(_) => popup_close(%d)" : "(_) => popup_hide(%d)",
443 wp->w_id); 445 wp->w_id);
444 if (get_lambda_tv_and_compile(&ptr, &tv, FALSE, &EVALARG_EVALUATE) == OK) 446 if (get_lambda_tv_and_compile(&ptr, &tv, FALSE, &EVALARG_EVALUATE) != OK)
445 { 447 return;
446 wp->w_popup_timer = create_timer(time, 0); 448
447 callback_T cb = get_callback(&tv); 449 wp->w_popup_timer = create_timer(time, 0);
448 if (cb.cb_name != NULL && !cb.cb_free_name) 450 callback_T cb = get_callback(&tv);
449 { 451 if (cb.cb_name != NULL && !cb.cb_free_name)
450 cb.cb_name = vim_strsave(cb.cb_name); 452 {
451 cb.cb_free_name = TRUE; 453 cb.cb_name = vim_strsave(cb.cb_name);
452 } 454 cb.cb_free_name = TRUE;
453 wp->w_popup_timer->tr_callback = cb; 455 }
454 clear_tv(&tv); 456 wp->w_popup_timer->tr_callback = cb;
455 } 457 clear_tv(&tv);
456 } 458 }
457 #endif 459 #endif
458 460
459 static poppos_T 461 static poppos_T
460 get_pos_entry(dict_T *d, int give_error) 462 get_pos_entry(dict_T *d, int give_error)
617 { 619 {
618 dictitem_T *di; 620 dictitem_T *di;
619 char_u *str; 621 char_u *str;
620 622
621 di = dict_find(dict, (char_u *)name, -1); 623 di = dict_find(dict, (char_u *)name, -1);
622 if (di != NULL) 624 if (di == NULL)
623 { 625 return;
624 if (di->di_tv.v_type != VAR_STRING) 626
625 semsg(_(e_invalid_value_for_argument_str), name); 627 if (di->di_tv.v_type != VAR_STRING)
626 else 628 semsg(_(e_invalid_value_for_argument_str), name);
627 { 629 else
628 str = tv_get_string(&di->di_tv); 630 {
629 if (*str != NUL) 631 str = tv_get_string(&di->di_tv);
630 *pval = vim_strsave(str); 632 if (*str != NUL)
631 } 633 *pval = vim_strsave(str);
632 } 634 }
633 } 635 }
634 636
635 /* 637 /*
636 * Scroll to show the line with the cursor. 638 * Scroll to show the line with the cursor.
988 else 990 else
989 wp->w_filter_mode = mode_str2flags(str); 991 wp->w_filter_mode = mode_str2flags(str);
990 } 992 }
991 993
992 di = dict_find(dict, (char_u *)"callback", -1); 994 di = dict_find(dict, (char_u *)"callback", -1);
993 if (di != NULL) 995 if (di == NULL)
994 { 996 return;
995 callback_T callback = get_callback(&di->di_tv); 997
996 998 callback_T callback = get_callback(&di->di_tv);
997 if (callback.cb_name != NULL) 999 if (callback.cb_name == NULL)
998 { 1000 return;
999 free_callback(&wp->w_close_cb); 1001
1000 set_callback(&wp->w_close_cb, &callback); 1002 free_callback(&wp->w_close_cb);
1001 if (callback.cb_free_name) 1003 set_callback(&wp->w_close_cb, &callback);
1002 vim_free(callback.cb_name); 1004 if (callback.cb_free_name)
1003 } 1005 vim_free(callback.cb_name);
1004 }
1005 } 1006 }
1006 1007
1007 /* 1008 /*
1008 * Go through the options in "dict" and apply them to popup window "wp". 1009 * Go through the options in "dict" and apply them to popup window "wp".
1009 * "create" is TRUE when creating a new popup window. 1010 * "create" is TRUE when creating a new popup window.
2713 { 2714 {
2714 #ifdef FEAT_TERMINAL 2715 #ifdef FEAT_TERMINAL
2715 if (error_if_term_popup_window()) 2716 if (error_if_term_popup_window())
2716 return; 2717 return;
2717 #endif 2718 #endif
2718 if ((wp->w_popup_flags & POPF_HIDDEN) == 0) 2719 if ((wp->w_popup_flags & POPF_HIDDEN) != 0)
2719 { 2720 return;
2720 wp->w_popup_flags |= POPF_HIDDEN; 2721
2721 // Do not decrement b_nwindows, we still reference the buffer. 2722 wp->w_popup_flags |= POPF_HIDDEN;
2722 redraw_all_later(UPD_NOT_VALID); 2723 // Do not decrement b_nwindows, we still reference the buffer.
2723 popup_mask_refresh = TRUE; 2724 redraw_all_later(UPD_NOT_VALID);
2724 } 2725 popup_mask_refresh = TRUE;
2725 } 2726 }
2726 2727
2727 /* 2728 /*
2728 * popup_hide({id}) 2729 * popup_hide({id})
2729 */ 2730 */
2736 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) 2737 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
2737 return; 2738 return;
2738 2739
2739 id = (int)tv_get_number(argvars); 2740 id = (int)tv_get_number(argvars);
2740 wp = find_popup_win(id); 2741 wp = find_popup_win(id);
2741 if (wp != NULL) 2742 if (wp == NULL)
2742 { 2743 return;
2743 popup_hide(wp); 2744
2744 wp->w_popup_flags |= POPF_HIDDEN_FORCE; 2745 popup_hide(wp);
2745 } 2746 wp->w_popup_flags |= POPF_HIDDEN_FORCE;
2746 } 2747 }
2747 2748
2748 void 2749 void
2749 popup_show(win_T *wp) 2750 popup_show(win_T *wp)
2750 { 2751 {
2751 if ((wp->w_popup_flags & POPF_HIDDEN) != 0) 2752 if ((wp->w_popup_flags & POPF_HIDDEN) == 0)
2752 { 2753 return;
2753 wp->w_popup_flags &= ~POPF_HIDDEN; 2754
2754 redraw_all_later(UPD_NOT_VALID); 2755 wp->w_popup_flags &= ~POPF_HIDDEN;
2755 popup_mask_refresh = TRUE; 2756 redraw_all_later(UPD_NOT_VALID);
2756 } 2757 popup_mask_refresh = TRUE;
2757 } 2758 }
2758 2759
2759 /* 2760 /*
2760 * popup_show({id}) 2761 * popup_show({id})
2761 */ 2762 */
2768 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) 2769 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
2769 return; 2770 return;
2770 2771
2771 id = (int)tv_get_number(argvars); 2772 id = (int)tv_get_number(argvars);
2772 wp = find_popup_win(id); 2773 wp = find_popup_win(id);
2773 if (wp != NULL) 2774 if (wp == NULL)
2774 { 2775 return;
2775 wp->w_popup_flags &= ~POPF_HIDDEN_FORCE; 2776
2776 popup_show(wp); 2777 wp->w_popup_flags &= ~POPF_HIDDEN_FORCE;
2778 popup_show(wp);
2777 #ifdef FEAT_QUICKFIX 2779 #ifdef FEAT_QUICKFIX
2778 if (wp->w_popup_flags & POPF_INFO) 2780 if (wp->w_popup_flags & POPF_INFO)
2779 pum_position_info_popup(wp); 2781 pum_position_info_popup(wp);
2780 #endif 2782 #endif
2781 }
2782 } 2783 }
2783 2784
2784 /* 2785 /*
2785 * popup_settext({id}, {text}) 2786 * popup_settext({id}, {text})
2786 */ 2787 */
2795 || check_for_string_or_list_arg(argvars, 1) == FAIL)) 2796 || check_for_string_or_list_arg(argvars, 1) == FAIL))
2796 return; 2797 return;
2797 2798
2798 id = (int)tv_get_number(&argvars[0]); 2799 id = (int)tv_get_number(&argvars[0]);
2799 wp = find_popup_win(id); 2800 wp = find_popup_win(id);
2800 if (wp != NULL) 2801 if (wp == NULL)
2801 { 2802 return;
2802 if (check_for_string_or_list_arg(argvars, 1) != FAIL) 2803
2803 { 2804 if (check_for_string_or_list_arg(argvars, 1) == FAIL)
2804 popup_set_buffer_text(wp->w_buffer, argvars[1]); 2805 return;
2805 redraw_win_later(wp, UPD_NOT_VALID); 2806
2806 popup_adjust_position(wp); 2807 popup_set_buffer_text(wp->w_buffer, argvars[1]);
2807 } 2808 redraw_win_later(wp, UPD_NOT_VALID);
2808 } 2809 popup_adjust_position(wp);
2809 } 2810 }
2810 2811
2811 static void 2812 static void
2812 popup_free(win_T *wp) 2813 popup_free(win_T *wp)
2813 { 2814 {
3009 int id; 3010 int id;
3010 win_T *wp; 3011 win_T *wp;
3011 int top_extra; 3012 int top_extra;
3012 int left_extra; 3013 int left_extra;
3013 3014
3014 if (rettv_dict_alloc(rettv) == OK) 3015 if (rettv_dict_alloc(rettv) == FAIL)
3015 { 3016 return;
3016 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) 3017
3017 return; 3018 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
3018 3019 return;
3019 id = (int)tv_get_number(argvars); 3020
3020 wp = find_popup_win(id); 3021 id = (int)tv_get_number(argvars);
3021 if (wp == NULL) 3022 wp = find_popup_win(id);
3022 return; // invalid {id} 3023 if (wp == NULL)
3023 top_extra = popup_top_extra(wp); 3024 return; // invalid {id}
3024 left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; 3025 top_extra = popup_top_extra(wp);
3025 3026 left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
3026 // we know how much space we need, avoid resizing halfway 3027
3027 dict = rettv->vval.v_dict; 3028 // we know how much space we need, avoid resizing halfway
3028 hash_lock_size(&dict->dv_hashtab, 11); 3029 dict = rettv->vval.v_dict;
3029 3030 hash_lock_size(&dict->dv_hashtab, 11);
3030 dict_add_number(dict, "line", wp->w_winrow + 1); 3031
3031 dict_add_number(dict, "col", wp->w_wincol + 1); 3032 dict_add_number(dict, "line", wp->w_winrow + 1);
3032 dict_add_number(dict, "width", wp->w_width + left_extra 3033 dict_add_number(dict, "col", wp->w_wincol + 1);
3033 + wp->w_popup_border[1] + wp->w_popup_padding[1]); 3034 dict_add_number(dict, "width", wp->w_width + left_extra
3034 dict_add_number(dict, "height", wp->w_height + top_extra 3035 + wp->w_popup_border[1] + wp->w_popup_padding[1]);
3035 + wp->w_popup_border[2] + wp->w_popup_padding[2]); 3036 dict_add_number(dict, "height", wp->w_height + top_extra
3036 3037 + wp->w_popup_border[2] + wp->w_popup_padding[2]);
3037 dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra); 3038
3038 dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra); 3039 dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra);
3039 dict_add_number(dict, "core_width", wp->w_width); 3040 dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra);
3040 dict_add_number(dict, "core_height", wp->w_height); 3041 dict_add_number(dict, "core_width", wp->w_width);
3041 3042 dict_add_number(dict, "core_height", wp->w_height);
3042 dict_add_number(dict, "scrollbar", wp->w_has_scrollbar); 3043
3043 dict_add_number(dict, "firstline", wp->w_topline); 3044 dict_add_number(dict, "scrollbar", wp->w_has_scrollbar);
3044 dict_add_number(dict, "lastline", wp->w_botline - 1); 3045 dict_add_number(dict, "firstline", wp->w_topline);
3045 dict_add_number(dict, "visible", 3046 dict_add_number(dict, "lastline", wp->w_botline - 1);
3046 win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0); 3047 dict_add_number(dict, "visible",
3047 3048 win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0);
3048 hash_unlock(&dict->dv_hashtab); 3049
3049 } 3050 hash_unlock(&dict->dv_hashtab);
3050 } 3051 }
3051 3052
3052 /* 3053 /*
3053 * popup_list() 3054 * popup_list()
3054 */ 3055 */
3100 3101
3101 if (array[0] == 0 && array[1] == 0 && array[2] == 0 && array[3] == 0) 3102 if (array[0] == 0 && array[1] == 0 && array[2] == 0 && array[3] == 0)
3102 return; 3103 return;
3103 3104
3104 list = list_alloc(); 3105 list = list_alloc();
3105 if (list != NULL) 3106 if (list == NULL)
3106 { 3107 return;
3107 dict_add_list(dict, name, list); 3108
3108 if (array[0] != 1 || array[1] != 1 || array[2] != 1 || array[3] != 1) 3109 dict_add_list(dict, name, list);
3109 for (i = 0; i < 4; ++i) 3110 if (array[0] != 1 || array[1] != 1 || array[2] != 1 || array[3] != 1)
3110 list_append_number(list, array[i]); 3111 for (i = 0; i < 4; ++i)
3111 } 3112 list_append_number(list, array[i]);
3112 } 3113 }
3113 3114
3114 /* 3115 /*
3115 * For popup_getoptions(): add a "borderhighlight" entry to "dict". 3116 * For popup_getoptions(): add a "borderhighlight" entry to "dict".
3116 */ 3117 */
3125 break; 3126 break;
3126 if (i == 4) 3127 if (i == 4)
3127 return; 3128 return;
3128 3129
3129 list = list_alloc(); 3130 list = list_alloc();
3130 if (list != NULL) 3131 if (list == NULL)
3131 { 3132 return;
3132 dict_add_list(dict, "borderhighlight", list); 3133
3133 for (i = 0; i < 4; ++i) 3134 dict_add_list(dict, "borderhighlight", list);
3134 list_append_string(list, wp->w_border_highlight[i], -1); 3135 for (i = 0; i < 4; ++i)
3135 } 3136 list_append_string(list, wp->w_border_highlight[i], -1);
3136 } 3137 }
3137 3138
3138 /* 3139 /*
3139 * For popup_getoptions(): add a "borderchars" entry to "dict". 3140 * For popup_getoptions(): add a "borderchars" entry to "dict".
3140 */ 3141 */
3151 break; 3152 break;
3152 if (i == 8) 3153 if (i == 8)
3153 return; 3154 return;
3154 3155
3155 list = list_alloc(); 3156 list = list_alloc();
3156 if (list != NULL) 3157 if (list == NULL)
3157 { 3158 return;
3158 dict_add_list(dict, "borderchars", list); 3159
3159 for (i = 0; i < 8; ++i) 3160 dict_add_list(dict, "borderchars", list);
3160 { 3161 for (i = 0; i < 8; ++i)
3161 len = mb_char2bytes(wp->w_border_char[i], buf); 3162 {
3162 list_append_string(list, buf, len); 3163 len = mb_char2bytes(wp->w_border_char[i], buf);
3163 } 3164 list_append_string(list, buf, len);
3164 } 3165 }
3165 } 3166 }
3166 3167
3167 /* 3168 /*
3168 * For popup_getoptions(): add a "moved" and "mousemoved" entry to "dict". 3169 * For popup_getoptions(): add a "moved" and "mousemoved" entry to "dict".
3179 list_append_number(list, wp->w_popup_lnum); 3180 list_append_number(list, wp->w_popup_lnum);
3180 list_append_number(list, wp->w_popup_mincol); 3181 list_append_number(list, wp->w_popup_mincol);
3181 list_append_number(list, wp->w_popup_maxcol); 3182 list_append_number(list, wp->w_popup_maxcol);
3182 } 3183 }
3183 list = list_alloc(); 3184 list = list_alloc();
3184 if (list != NULL) 3185 if (list == NULL)
3185 { 3186 return;
3186 dict_add_list(dict, "mousemoved", list); 3187
3187 list_append_number(list, wp->w_popup_mouse_row); 3188 dict_add_list(dict, "mousemoved", list);
3188 list_append_number(list, wp->w_popup_mouse_mincol); 3189 list_append_number(list, wp->w_popup_mouse_row);
3189 list_append_number(list, wp->w_popup_mouse_maxcol); 3190 list_append_number(list, wp->w_popup_mouse_mincol);
3190 } 3191 list_append_number(list, wp->w_popup_mouse_maxcol);
3191 } 3192 }
3192 3193
3193 /* 3194 /*
3194 * popup_getoptions({id}) 3195 * popup_getoptions({id})
3195 */ 3196 */
3200 int id; 3201 int id;
3201 win_T *wp; 3202 win_T *wp;
3202 tabpage_T *tp; 3203 tabpage_T *tp;
3203 int i; 3204 int i;
3204 3205
3205 if (rettv_dict_alloc(rettv) == OK) 3206 if (rettv_dict_alloc(rettv) == FAIL)
3206 { 3207 return;
3207 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL) 3208
3208 return; 3209 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
3209 3210 return;
3210 id = (int)tv_get_number(argvars); 3211
3211 wp = find_popup_win(id); 3212 id = (int)tv_get_number(argvars);
3212 if (wp == NULL) 3213 wp = find_popup_win(id);
3213 return; 3214 if (wp == NULL)
3214 3215 return;
3215 dict = rettv->vval.v_dict; 3216
3216 dict_add_number(dict, "line", wp->w_wantline); 3217 dict = rettv->vval.v_dict;
3217 dict_add_number(dict, "col", wp->w_wantcol); 3218 dict_add_number(dict, "line", wp->w_wantline);
3218 dict_add_number(dict, "minwidth", wp->w_minwidth); 3219 dict_add_number(dict, "col", wp->w_wantcol);
3219 dict_add_number(dict, "minheight", wp->w_minheight); 3220 dict_add_number(dict, "minwidth", wp->w_minwidth);
3220 dict_add_number(dict, "maxheight", wp->w_maxheight); 3221 dict_add_number(dict, "minheight", wp->w_minheight);
3221 dict_add_number(dict, "maxwidth", wp->w_maxwidth); 3222 dict_add_number(dict, "maxheight", wp->w_maxheight);
3222 dict_add_number(dict, "firstline", wp->w_firstline); 3223 dict_add_number(dict, "maxwidth", wp->w_maxwidth);
3223 dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); 3224 dict_add_number(dict, "firstline", wp->w_firstline);
3224 dict_add_number(dict, "zindex", wp->w_zindex); 3225 dict_add_number(dict, "scrollbar", wp->w_want_scrollbar);
3225 dict_add_number(dict, "fixed", wp->w_popup_fixed); 3226 dict_add_number(dict, "zindex", wp->w_zindex);
3226 if (wp->w_popup_prop_type && win_valid_any_tab(wp->w_popup_prop_win)) 3227 dict_add_number(dict, "fixed", wp->w_popup_fixed);
3227 { 3228 if (wp->w_popup_prop_type && win_valid_any_tab(wp->w_popup_prop_win))
3228 proptype_T *pt = text_prop_type_by_id( 3229 {
3229 wp->w_popup_prop_win->w_buffer, 3230 proptype_T *pt = text_prop_type_by_id(
3230 wp->w_popup_prop_type); 3231 wp->w_popup_prop_win->w_buffer,
3231 3232 wp->w_popup_prop_type);
3232 if (pt != NULL) 3233
3233 dict_add_string(dict, "textprop", pt->pt_name); 3234 if (pt != NULL)
3234 dict_add_number(dict, "textpropwin", wp->w_popup_prop_win->w_id); 3235 dict_add_string(dict, "textprop", pt->pt_name);
3235 dict_add_number(dict, "textpropid", wp->w_popup_prop_id); 3236 dict_add_number(dict, "textpropwin", wp->w_popup_prop_win->w_id);
3236 } 3237 dict_add_number(dict, "textpropid", wp->w_popup_prop_id);
3237 dict_add_string(dict, "title", wp->w_popup_title); 3238 }
3238 dict_add_number(dict, "wrap", wp->w_p_wrap); 3239 dict_add_string(dict, "title", wp->w_popup_title);
3239 dict_add_number(dict, "drag", (wp->w_popup_flags & POPF_DRAG) != 0); 3240 dict_add_number(dict, "wrap", wp->w_p_wrap);
3240 dict_add_number(dict, "dragall", 3241 dict_add_number(dict, "drag", (wp->w_popup_flags & POPF_DRAG) != 0);
3241 (wp->w_popup_flags & POPF_DRAGALL) != 0); 3242 dict_add_number(dict, "dragall",
3242 dict_add_number(dict, "mapping", 3243 (wp->w_popup_flags & POPF_DRAGALL) != 0);
3243 (wp->w_popup_flags & POPF_MAPPING) != 0); 3244 dict_add_number(dict, "mapping",
3244 dict_add_number(dict, "resize", (wp->w_popup_flags & POPF_RESIZE) != 0); 3245 (wp->w_popup_flags & POPF_MAPPING) != 0);
3245 dict_add_number(dict, "posinvert", 3246 dict_add_number(dict, "resize", (wp->w_popup_flags & POPF_RESIZE) != 0);
3246 (wp->w_popup_flags & POPF_POSINVERT) != 0); 3247 dict_add_number(dict, "posinvert",
3247 dict_add_number(dict, "cursorline", 3248 (wp->w_popup_flags & POPF_POSINVERT) != 0);
3248 (wp->w_popup_flags & POPF_CURSORLINE) != 0); 3249 dict_add_number(dict, "cursorline",
3249 dict_add_string(dict, "highlight", wp->w_p_wcr); 3250 (wp->w_popup_flags & POPF_CURSORLINE) != 0);
3250 if (wp->w_scrollbar_highlight != NULL) 3251 dict_add_string(dict, "highlight", wp->w_p_wcr);
3251 dict_add_string(dict, "scrollbarhighlight", 3252 if (wp->w_scrollbar_highlight != NULL)
3252 wp->w_scrollbar_highlight); 3253 dict_add_string(dict, "scrollbarhighlight",
3253 if (wp->w_thumb_highlight != NULL) 3254 wp->w_scrollbar_highlight);
3254 dict_add_string(dict, "thumbhighlight", wp->w_thumb_highlight); 3255 if (wp->w_thumb_highlight != NULL)
3255 3256 dict_add_string(dict, "thumbhighlight", wp->w_thumb_highlight);
3256 // find the tabpage that holds this popup 3257
3257 i = 1; 3258 // find the tabpage that holds this popup
3258 FOR_ALL_TABPAGES(tp) 3259 i = 1;
3259 { 3260 FOR_ALL_TABPAGES(tp)
3260 win_T *twp; 3261 {
3261 3262 win_T *twp;
3262 FOR_ALL_POPUPWINS_IN_TAB(tp, twp) 3263
3263 if (twp->w_id == id) 3264 FOR_ALL_POPUPWINS_IN_TAB(tp, twp)
3264 break; 3265 if (twp->w_id == id)
3265 if (twp != NULL)
3266 break; 3266 break;
3267 ++i; 3267 if (twp != NULL)
3268 } 3268 break;
3269 if (tp == NULL) 3269 ++i;
3270 i = -1; // must be global 3270 }
3271 else if (tp == curtab) 3271 if (tp == NULL)
3272 i = 0; 3272 i = -1; // must be global
3273 dict_add_number(dict, "tabpage", i); 3273 else if (tp == curtab)
3274 3274 i = 0;
3275 get_padding_border(dict, wp->w_popup_padding, "padding"); 3275 dict_add_number(dict, "tabpage", i);
3276 get_padding_border(dict, wp->w_popup_border, "border"); 3276
3277 get_borderhighlight(dict, wp); 3277 get_padding_border(dict, wp->w_popup_padding, "padding");
3278 get_borderchars(dict, wp); 3278 get_padding_border(dict, wp->w_popup_border, "border");
3279 get_moved_list(dict, wp); 3279 get_borderhighlight(dict, wp);
3280 3280 get_borderchars(dict, wp);
3281 if (wp->w_filter_cb.cb_name != NULL) 3281 get_moved_list(dict, wp);
3282 dict_add_callback(dict, "filter", &wp->w_filter_cb); 3282
3283 if (wp->w_close_cb.cb_name != NULL) 3283 if (wp->w_filter_cb.cb_name != NULL)
3284 dict_add_callback(dict, "callback", &wp->w_close_cb); 3284 dict_add_callback(dict, "filter", &wp->w_filter_cb);
3285 3285 if (wp->w_close_cb.cb_name != NULL)
3286 for (i = 0; i < (int)ARRAY_LENGTH(poppos_entries); ++i) 3286 dict_add_callback(dict, "callback", &wp->w_close_cb);
3287 if (wp->w_popup_pos == poppos_entries[i].pp_val) 3287
3288 { 3288 for (i = 0; i < (int)ARRAY_LENGTH(poppos_entries); ++i)
3289 dict_add_string(dict, "pos", 3289 if (wp->w_popup_pos == poppos_entries[i].pp_val)
3290 (char_u *)poppos_entries[i].pp_name); 3290 {
3291 break; 3291 dict_add_string(dict, "pos",
3292 } 3292 (char_u *)poppos_entries[i].pp_name);
3293 3293 break;
3294 dict_add_string(dict, "close", (char_u *)( 3294 }
3295 wp->w_popup_close == POPCLOSE_BUTTON ? "button" 3295
3296 : wp->w_popup_close == POPCLOSE_CLICK ? "click" : "none")); 3296 dict_add_string(dict, "close", (char_u *)(
3297 wp->w_popup_close == POPCLOSE_BUTTON ? "button"
3298 : wp->w_popup_close == POPCLOSE_CLICK ? "click" : "none"));
3297 3299
3298 # if defined(FEAT_TIMERS) 3300 # if defined(FEAT_TIMERS)
3299 dict_add_number(dict, "time", wp->w_popup_timer != NULL 3301 dict_add_number(dict, "time", wp->w_popup_timer != NULL
3300 ? (long)wp->w_popup_timer->tr_interval : 0L); 3302 ? (long)wp->w_popup_timer->tr_interval : 0L);
3301 # endif 3303 # endif
3302 }
3303 } 3304 }
3304 3305
3305 # if defined(FEAT_TERMINAL) || defined(PROTO) 3306 # if defined(FEAT_TERMINAL) || defined(PROTO)
3306 /* 3307 /*
3307 * Return TRUE if the current window is running a terminal in a popup window. 3308 * Return TRUE if the current window is running a terminal in a popup window.
3638 * Set flags in popup_transparent[] for window "wp" to "val". 3639 * Set flags in popup_transparent[] for window "wp" to "val".
3639 */ 3640 */
3640 static void 3641 static void
3641 update_popup_transparent(win_T *wp, int val) 3642 update_popup_transparent(win_T *wp, int val)
3642 { 3643 {
3643 if (wp->w_popup_mask != NULL) 3644 if (wp->w_popup_mask == NULL)
3644 { 3645 return;
3645 int width = popup_width(wp); 3646
3646 int height = popup_height(wp); 3647 int width = popup_width(wp);
3647 listitem_T *lio, *li; 3648 int height = popup_height(wp);
3648 int cols, cole; 3649 listitem_T *lio, *li;
3649 int lines, linee; 3650 int cols, cole;
3650 int col, line; 3651 int lines, linee;
3651 3652 int col, line;
3652 FOR_ALL_LIST_ITEMS(wp->w_popup_mask, lio) 3653
3653 { 3654 FOR_ALL_LIST_ITEMS(wp->w_popup_mask, lio)
3654 li = lio->li_tv.vval.v_list->lv_first; 3655 {
3655 cols = tv_get_number(&li->li_tv); 3656 li = lio->li_tv.vval.v_list->lv_first;
3656 if (cols < 0) 3657 cols = tv_get_number(&li->li_tv);
3657 cols = width + cols + 1; 3658 if (cols < 0)
3658 li = li->li_next; 3659 cols = width + cols + 1;
3659 cole = tv_get_number(&li->li_tv); 3660 li = li->li_next;
3660 if (cole < 0) 3661 cole = tv_get_number(&li->li_tv);
3661 cole = width + cole + 1; 3662 if (cole < 0)
3662 li = li->li_next; 3663 cole = width + cole + 1;
3663 lines = tv_get_number(&li->li_tv); 3664 li = li->li_next;
3664 if (lines < 0) 3665 lines = tv_get_number(&li->li_tv);
3665 lines = height + lines + 1; 3666 if (lines < 0)
3666 li = li->li_next; 3667 lines = height + lines + 1;
3667 linee = tv_get_number(&li->li_tv); 3668 li = li->li_next;
3668 if (linee < 0) 3669 linee = tv_get_number(&li->li_tv);
3669 linee = height + linee + 1; 3670 if (linee < 0)
3670 3671 linee = height + linee + 1;
3671 --cols; 3672
3672 cols -= wp->w_popup_leftoff; 3673 --cols;
3673 if (cols < 0) 3674 cols -= wp->w_popup_leftoff;
3674 cols = 0; 3675 if (cols < 0)
3675 cole -= wp->w_popup_leftoff; 3676 cols = 0;
3676 --lines; 3677 cole -= wp->w_popup_leftoff;
3677 if (lines < 0) 3678 --lines;
3678 lines = 0; 3679 if (lines < 0)
3679 for (line = lines; line < linee 3680 lines = 0;
3680 && line + wp->w_winrow < screen_Rows; ++line) 3681 for (line = lines; line < linee
3681 for (col = cols; col < cole 3682 && line + wp->w_winrow < screen_Rows; ++line)
3682 && col + wp->w_wincol < screen_Columns; ++col) 3683 for (col = cols; col < cole
3683 popup_transparent[(line + wp->w_winrow) * screen_Columns 3684 && col + wp->w_wincol < screen_Columns; ++col)
3684 + col + wp->w_wincol] = val; 3685 popup_transparent[(line + wp->w_winrow) * screen_Columns
3685 } 3686 + col + wp->w_wincol] = val;
3686 } 3687 }
3687 } 3688 }
3688 3689
3689 /* 3690 /*
3690 * Only called when popup window "wp" is hidden: If the window is positioned 3691 * Only called when popup window "wp" is hidden: If the window is positioned
4506 * Returns NULL if something failed. 4507 * Returns NULL if something failed.
4507 */ 4508 */
4508 win_T * 4509 win_T *
4509 popup_get_message_win(void) 4510 popup_get_message_win(void)
4510 { 4511 {
4512 if (message_win != NULL)
4513 return message_win;
4514
4515 int i;
4516
4517 message_win = popup_create(NULL, NULL, TYPE_MESSAGE_WIN);
4518
4511 if (message_win == NULL) 4519 if (message_win == NULL)
4512 { 4520 return NULL;
4513 int i; 4521
4514 4522 // use the full screen width
4515 message_win = popup_create(NULL, NULL, TYPE_MESSAGE_WIN); 4523 message_win->w_width = Columns;
4516 4524
4517 if (message_win == NULL) 4525 // position at bottom of screen
4518 return NULL; 4526 message_win->w_popup_pos = POPPOS_BOTTOM;
4519 4527 message_win->w_wantcol = 1;
4520 // use the full screen width 4528 message_win->w_minwidth = 9999;
4521 message_win->w_width = Columns; 4529 message_win->w_firstline = -1;
4522 4530
4523 // position at bottom of screen 4531 // no padding, border at the top
4524 message_win->w_popup_pos = POPPOS_BOTTOM; 4532 for (i = 0; i < 4; ++i)
4525 message_win->w_wantcol = 1; 4533 message_win->w_popup_padding[i] = 0;
4526 message_win->w_minwidth = 9999; 4534 for (i = 1; i < 4; ++i)
4527 message_win->w_firstline = -1; 4535 message_win->w_popup_border[i] = 0;
4528 4536
4529 // no padding, border at the top 4537 if (message_win->w_popup_timer != NULL)
4530 for (i = 0; i < 4; ++i) 4538 message_win->w_popup_timer->tr_keep = TRUE;
4531 message_win->w_popup_padding[i] = 0;
4532 for (i = 1; i < 4; ++i)
4533 message_win->w_popup_border[i] = 0;
4534
4535 if (message_win->w_popup_timer != NULL)
4536 message_win->w_popup_timer->tr_keep = TRUE;
4537 }
4538 return message_win; 4539 return message_win;
4539 } 4540 }
4540 4541
4541 /* 4542 /*
4542 * If the message window is not visible: show it 4543 * If the message window is not visible: show it
4543 * If the message window is visible: reset the timeout 4544 * If the message window is visible: reset the timeout
4544 */ 4545 */
4545 void 4546 void
4546 popup_show_message_win(void) 4547 popup_show_message_win(void)
4547 { 4548 {
4548 if (message_win != NULL) 4549 if (message_win == NULL)
4549 { 4550 return;
4550 if ((message_win->w_popup_flags & POPF_HIDDEN) != 0) 4551
4551 { 4552 if ((message_win->w_popup_flags & POPF_HIDDEN) != 0)
4552 // the highlight may have changed. 4553 {
4553 popup_update_color(message_win, TYPE_MESSAGE_WIN); 4554 // the highlight may have changed.
4554 popup_show(message_win); 4555 popup_update_color(message_win, TYPE_MESSAGE_WIN);
4555 } 4556 popup_show(message_win);
4556 start_message_win_timer = TRUE; 4557 }
4557 } 4558 start_message_win_timer = TRUE;
4558 } 4559 }
4559 4560
4560 static void 4561 static void
4561 may_start_message_win_timer(win_T *wp) 4562 may_start_message_win_timer(win_T *wp)
4562 { 4563 {
4662 * Set the title of the popup window to the file name. 4663 * Set the title of the popup window to the file name.
4663 */ 4664 */
4664 void 4665 void
4665 popup_set_title(win_T *wp) 4666 popup_set_title(win_T *wp)
4666 { 4667 {
4667 if (wp->w_buffer->b_fname != NULL) 4668 if (wp->w_buffer->b_fname == NULL)
4668 { 4669 return;
4669 char_u dirname[MAXPATHL]; 4670
4670 size_t len; 4671 char_u dirname[MAXPATHL];
4671 4672 size_t len;
4672 mch_dirname(dirname, MAXPATHL); 4673
4673 shorten_buf_fname(wp->w_buffer, dirname, FALSE); 4674 mch_dirname(dirname, MAXPATHL);
4674 4675 shorten_buf_fname(wp->w_buffer, dirname, FALSE);
4675 vim_free(wp->w_popup_title); 4676
4676 len = STRLEN(wp->w_buffer->b_fname) + 3; 4677 vim_free(wp->w_popup_title);
4677 wp->w_popup_title = alloc((int)len); 4678 len = STRLEN(wp->w_buffer->b_fname) + 3;
4678 if (wp->w_popup_title != NULL) 4679 wp->w_popup_title = alloc((int)len);
4679 vim_snprintf((char *)wp->w_popup_title, len, " %s ", 4680 if (wp->w_popup_title != NULL)
4680 wp->w_buffer->b_fname); 4681 vim_snprintf((char *)wp->w_popup_title, len, " %s ",
4681 redraw_win_later(wp, UPD_VALID); 4682 wp->w_buffer->b_fname);
4682 } 4683 redraw_win_later(wp, UPD_VALID);
4683 } 4684 }
4684 4685
4685 # if defined(FEAT_QUICKFIX) || defined(PROTO) 4686 # if defined(FEAT_QUICKFIX) || defined(PROTO)
4686 /* 4687 /*
4687 * If there is a preview window, update the title. 4688 * If there is a preview window, update the title.