comparison src/popupwin.c @ 16908:df06694b761b v8.1.1455

patch 8.1.1455: popup_atcursor() not completely implemented commit https://github.com/vim/vim/commit/1762731f2039d78fc8ddd785c3d3b52e5968c0f1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 2 19:53:44 2019 +0200 patch 8.1.1455: popup_atcursor() not completely implemented Problem: Popup_atcursor() not completely implemented. Solution: Add the default for the "moved" property.
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Jun 2019 20:00:06 +0200
parents 9138e2c60bf1
children 03f3a9ca2770
comparison
equal deleted inserted replaced
16907:eaf7f6fefdb6 16908:df06694b761b
136 } 136 }
137 } 137 }
138 } 138 }
139 139
140 /* 140 /*
141 * Used when popup options contain "moved": set default moved values.
142 */
143 static void
144 set_moved_values(win_T *wp)
145 {
146 wp->w_popup_curwin = curwin;
147 wp->w_popup_lnum = curwin->w_cursor.lnum;
148 wp->w_popup_mincol = curwin->w_cursor.col;
149 wp->w_popup_maxcol = curwin->w_cursor.col;
150 }
151
152 /*
153 * Used when popup options contain "moved" with "word" or "WORD".
154 */
155 static void
156 set_moved_columns(win_T *wp, int flags)
157 {
158 char_u *ptr;
159 int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR);
160
161 if (len > 0)
162 {
163 wp->w_popup_mincol = (int)(ptr - ml_get_curline());
164 wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
165 }
166 }
167
168 /*
141 * Go through the options in "dict" and apply them to buffer "buf" displayed in 169 * Go through the options in "dict" and apply them to buffer "buf" displayed in
142 * popup window "wp". 170 * popup window "wp".
143 * When called from f_popup_atcursor() "atcursor" is TRUE.
144 */ 171 */
145 static void 172 static void
146 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor) 173 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict)
147 { 174 {
148 int nr; 175 int nr;
149 char_u *str; 176 char_u *str;
150 dictitem_T *di; 177 dictitem_T *di;
151 int i; 178 int i;
152 179
153 wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth"); 180 wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth");
154 wp->w_minheight = dict_get_number(dict, (char_u *)"minheight"); 181 wp->w_minheight = dict_get_number(dict, (char_u *)"minheight");
155 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth"); 182 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth");
156 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight"); 183 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight");
157
158 if (atcursor)
159 {
160 wp->w_popup_pos = POPPOS_BOTLEFT;
161 setcursor_mayforce(TRUE);
162 wp->w_wantline = screen_screenrow();
163 if (wp->w_wantline == 0) // cursor in first line
164 {
165 wp->w_wantline = 2;
166 wp->w_popup_pos = POPPOS_TOPLEFT;
167 }
168 wp->w_wantcol = screen_screencol() + 1;
169 }
170 184
171 get_pos_options(wp, dict); 185 get_pos_options(wp, dict);
172 186
173 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); 187 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex");
174 188
287 } 301 }
288 302
289 di = dict_find(dict, (char_u *)"moved", -1); 303 di = dict_find(dict, (char_u *)"moved", -1);
290 if (di != NULL) 304 if (di != NULL)
291 { 305 {
292 wp->w_popup_curwin = curwin; 306 set_moved_values(wp);
293 wp->w_popup_lnum = curwin->w_cursor.lnum;
294 wp->w_popup_mincol = curwin->w_cursor.col;
295 wp->w_popup_maxcol = curwin->w_cursor.col;
296 if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL) 307 if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
297 { 308 {
298 char_u *s = di->di_tv.vval.v_string; 309 char_u *s = di->di_tv.vval.v_string;
299 int flags = 0; 310 int flags = 0;
300 311
303 else if (STRCMP(s, "WORD") == 0) 314 else if (STRCMP(s, "WORD") == 0)
304 flags = FIND_STRING; 315 flags = FIND_STRING;
305 else if (STRCMP(s, "any") != 0) 316 else if (STRCMP(s, "any") != 0)
306 semsg(_(e_invarg2), s); 317 semsg(_(e_invarg2), s);
307 if (flags != 0) 318 if (flags != 0)
308 { 319 set_moved_columns(wp, flags);
309 char_u *ptr;
310 int len = find_ident_under_cursor(&ptr, flags);
311
312 if (len > 0)
313 {
314 wp->w_popup_mincol = (int)(ptr - ml_get_curline());
315 wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
316 }
317 }
318 } 320 }
319 else if (di->di_tv.v_type == VAR_LIST 321 else if (di->di_tv.v_type == VAR_LIST
320 && di->di_tv.vval.v_list != NULL 322 && di->di_tv.vval.v_list != NULL
321 && di->di_tv.vval.v_list->lv_len == 2) 323 && di->di_tv.vval.v_list->lv_len == 2)
322 { 324 {
552 } 554 }
553 555
554 wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); 556 wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer);
555 } 557 }
556 558
559 typedef enum
560 {
561 TYPE_NORMAL,
562 TYPE_ATCURSOR
563 } create_type_T;
564
557 /* 565 /*
558 * popup_create({text}, {options}) 566 * popup_create({text}, {options})
559 * popup_atcursor({text}, {options}) 567 * popup_atcursor({text}, {options})
560 * When called from f_popup_atcursor() "atcursor" is TRUE. 568 * When called from f_popup_atcursor() "atcursor" is TRUE.
561 */ 569 */
562 static void 570 static void
563 popup_create(typval_T *argvars, typval_T *rettv, int atcursor) 571 popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
564 { 572 {
565 win_T *wp; 573 win_T *wp;
566 buf_T *buf; 574 buf_T *buf;
567 dict_T *d; 575 dict_T *d;
568 int nr; 576 int nr;
650 // Delete the line of the empty buffer. 658 // Delete the line of the empty buffer.
651 curbuf = buf; 659 curbuf = buf;
652 ml_delete(buf->b_ml.ml_line_count, FALSE); 660 ml_delete(buf->b_ml.ml_line_count, FALSE);
653 curbuf = curwin->w_buffer; 661 curbuf = curwin->w_buffer;
654 662
663 if (type == TYPE_ATCURSOR)
664 {
665 wp->w_popup_pos = POPPOS_BOTLEFT;
666 setcursor_mayforce(TRUE);
667 wp->w_wantline = screen_screenrow();
668 if (wp->w_wantline == 0) // cursor in first line
669 {
670 wp->w_wantline = 2;
671 wp->w_popup_pos = POPPOS_TOPLEFT;
672 }
673 wp->w_wantcol = screen_screencol() + 1;
674 set_moved_values(wp);
675 set_moved_columns(wp, FIND_STRING);
676 }
677
655 // Deal with options. 678 // Deal with options.
656 apply_options(wp, buf, argvars[1].vval.v_dict, atcursor); 679 apply_options(wp, buf, argvars[1].vval.v_dict);
657 680
658 // set default values 681 // set default values
659 if (wp->w_zindex == 0) 682 if (wp->w_zindex == 0)
660 wp->w_zindex = 50; 683 wp->w_zindex = 50;
661 684
670 * popup_create({text}, {options}) 693 * popup_create({text}, {options})
671 */ 694 */
672 void 695 void
673 f_popup_create(typval_T *argvars, typval_T *rettv) 696 f_popup_create(typval_T *argvars, typval_T *rettv)
674 { 697 {
675 popup_create(argvars, rettv, FALSE); 698 popup_create(argvars, rettv, TYPE_NORMAL);
676 } 699 }
677 700
678 /* 701 /*
679 * popup_atcursor({text}, {options}) 702 * popup_atcursor({text}, {options})
680 */ 703 */
681 void 704 void
682 f_popup_atcursor(typval_T *argvars, typval_T *rettv) 705 f_popup_atcursor(typval_T *argvars, typval_T *rettv)
683 { 706 {
684 popup_create(argvars, rettv, TRUE); 707 popup_create(argvars, rettv, TYPE_ATCURSOR);
685 } 708 }
686 709
687 /* 710 /*
688 * Find the popup window with window-ID "id". 711 * Find the popup window with window-ID "id".
689 * If the popup window does not exist NULL is returned. 712 * If the popup window does not exist NULL is returned.