To: vim_dev@googlegroups.com Subject: Patch 8.1.1928 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1928 Problem: Popup windows don't move with the text when making changes. Solution: Add the 'textprop" property to the popup window options, position the popup relative to a text property. (closes #4560) No tests yet. Files: runtime/doc/popup.txt, src/textprop.c, src/proto/textprop.pro, src/structs.h, src/popupwin.c, src/proto/popupwin.pro, src/move.c, src/proto/move.pro, src/window.c *** ../vim-8.1.1927/runtime/doc/popup.txt 2019-08-21 18:30:58.882719474 +0200 --- runtime/doc/popup.txt 2019-08-25 22:23:06.715836619 +0200 *************** *** 16,21 **** --- 16,22 ---- 3. Usage |popup-usage| popup_create() arguments |popup_create-arguments| Popup text properties |popup-props| + Position popup with textprop |popup-textprop-pos| Popup filter |popup-filter| Popup callback |popup-callback| Popup scrollbar |popup-scrollbar| *************** *** 325,330 **** --- 326,334 ---- the current tabpage and a positive number for a popup on another tabpage. + "textprop", "textpropid" and "textpropwin" are only present + when "textprop" was set. + If popup window {id} is not found an empty Dict is returned. *************** *** 507,523 **** --- 511,539 ---- the line of the cursor and add or subtract a number of lines. If omitted the popup is vertically centered. The first line is 1. + When using "textprop" the number is relative to the + text property and can be negative. col Screen column where to position the popup. Can use a number or "cursor" to use the column of the cursor, "cursor+9" or "cursor-9" to add or subtract a number of columns. If omitted the popup is horizontally centered. The first column is 1. + When using "textprop" the number is relative to the + text property and can be negative. pos "topleft", "topright", "botleft" or "botright": defines what corner of the popup "line" and "col" are used for. When not set "topleft" is used. Alternatively "center" can be used to position the popup in the center of the Vim window, in which case "line" and "col" are ignored. + textprop When present the popup is positioned next to a text + property with this name and will move when the text + property moves. Use an empty string to remove. See + |popup-textprop-pos|. + textpropwin What window to search for the text property. When + omitted or invalid the current window is used. + textpropid Used to identify the text property when "textprop" is + present. Use zero to reset. fixed When FALSE (the default), and: - "pos" is "botleft" or "topleft", and - "wrap" is off, and *************** *** 670,675 **** --- 686,757 ---- |prop_type_add()| + POSITION POPUP WITH TEXTPROP *popup-textprop-pos* + + Positioning a popup next to a text property causes the popup to move when text + is inserted or deleted. The popup functions like a tooltip. + + These steps are needed to make this work: + + - Define a text property type, it defines the name. > + call prop_type_add('popupMarker', {}) + + - Place a text property at the desired text: > + let lnum = {line of the text} + let col = {start column of the text} + let len = {length of the text} + let propId = {arbitrary but unique number} + call prop_add(lnum, col, #{ + \ length: len, + \ type: 'popupMarker', + \ id: propId, + \ }) + + - Create a popup: > + let winid = popup_create('the text', #{ + \ pos: 'botleft', + \ textprop: 'popupMarker', + \ textpropid: propId, + \ border: [], + \ padding: [0,1,0,1], + \ close: 'click', + \ }) + + By default the popup is positioned at the corner of the text, opposite of the + "pos" specified for the popup. Thus when the popup uses "botleft", the + bottom-left corner of the popup is positioned next to the top-right corner of + the text property: + +----------+ + | the text | + +----------+ + just some PROPERTY as an example + + Here the text property is on "PROPERTY". Move the popup to the left by + passing a negative "col" value to popup_create(). With "col: -5" you get: + + +----------+ + | the text | + +----------+ + just some PROPERTY as an example + + If the text property moves out of view then the popup will be hidden. + If the window for which the popup was defined is closed, the popup is closed. + + If the popup cannot fit in the desired position, it may show at a nearby + position. + + Some hints: + - To avoid collision with other plugins the text property type name has to be + unique. You can also use the "bufnr" item to make it local to a buffer. + - You can leave out the text property ID if there is only ever one text + property visible. + - The popup may be in the way of what the user is doing, making it close with + a click, as in the example above, helps for that. + - If the text property is removed the popup is closed. Use something like + this: > + call prop_remove(#{type: 'popupMarker', id: propId}) + + POPUP FILTER *popup-filter* A callback that gets any typed keys while a popup is displayed. The filter is *** ../vim-8.1.1927/src/textprop.c 2019-08-20 20:13:40.334821916 +0200 --- src/textprop.c 2019-08-25 21:06:20.287165069 +0200 *************** *** 91,96 **** --- 91,110 ---- } /* + * Get the prop type ID of "name". + * When not found return zero. + */ + int + find_prop_type_id(char_u *name, buf_T *buf) + { + proptype_T *pt = find_prop(name, buf); + + if (pt == NULL) + return 0; + return pt->pt_id; + } + + /* * Lookup a property type by name. First in "buf" and when not found in the * global types. * When not found gives an error message and returns NULL. *************** *** 368,373 **** --- 382,421 ---- } /* + * Find text property "type_id" in the visible lines of window "wp". + * Match "id" when it is > 0. + * Returns FAIL when not found. + */ + int + find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop, + linenr_T *found_lnum) + { + linenr_T lnum; + char_u *props; + int count; + int i; + + // w_botline may not have been updated yet. + if (wp->w_botline > wp->w_buffer->b_ml.ml_line_count) + wp->w_botline = wp->w_buffer->b_ml.ml_line_count + 1; + for (lnum = wp->w_topline; lnum < wp->w_botline; ++lnum) + { + count = get_text_props(wp->w_buffer, lnum, &props, FALSE); + for (i = 0; i < count; ++i) + { + mch_memmove(prop, props + i * sizeof(textprop_T), + sizeof(textprop_T)); + if (prop->tp_type == type_id && (id <= 0 || prop->tp_id == id)) + { + *found_lnum = lnum; + return OK; + } + } + } + return FAIL; + } + + /* * Set the text properties for line "lnum" to "props" with length "len". * If "len" is zero text properties are removed, "props" is not used. * Any existing text properties are dropped. *** ../vim-8.1.1927/src/proto/textprop.pro 2019-08-20 20:13:40.334821916 +0200 --- src/proto/textprop.pro 2019-08-25 18:06:52.337377089 +0200 *************** *** 1,7 **** --- 1,9 ---- /* textprop.c */ + int find_prop_type_id(char_u *name, buf_T *buf); void f_prop_add(typval_T *argvars, typval_T *rettv); void prop_add_common(linenr_T start_lnum, colnr_T start_col, dict_T *dict, buf_T *default_buf, typval_T *dict_arg); int get_text_props(buf_T *buf, linenr_T lnum, char_u **props, int will_change); + int find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop, linenr_T *found_lnum); proptype_T *text_prop_type_by_id(buf_T *buf, int id); void f_prop_clear(typval_T *argvars, typval_T *rettv); void f_prop_list(typval_T *argvars, typval_T *rettv); *** ../vim-8.1.1927/src/structs.h 2019-08-21 14:36:29.395376065 +0200 --- src/structs.h 2019-08-25 20:27:22.361614410 +0200 *************** *** 3022,3027 **** --- 3022,3030 ---- char_u *w_popup_title; poppos_T w_popup_pos; int w_popup_fixed; // do not shift popup to fit on screen + int w_popup_prop_type; // when not zero: textprop type ID + win_T *w_popup_prop_win; // window to search for textprop + int w_popup_prop_id; // when not zero: textprop ID int w_zindex; int w_minheight; // "minheight" for popup window int w_minwidth; // "minwidth" for popup window *************** *** 3041,3048 **** int w_popup_leftoff; // columns left of the screen int w_popup_rightoff; // columns right of the screen ! varnumber_T w_popup_last_changedtick; // b:changedtick when position was ! // computed callback_T w_close_cb; // popup close callback callback_T w_filter_cb; // popup filter callback --- 3044,3057 ---- int w_popup_leftoff; // columns left of the screen int w_popup_rightoff; // columns right of the screen ! varnumber_T w_popup_last_changedtick; // b:changedtick of popup buffer ! // when position was computed ! varnumber_T w_popup_prop_changedtick; // b:changedtick of buffer with ! // w_popup_prop_type when position ! // was computed ! int w_popup_prop_topline; // w_topline of window with ! // w_popup_prop_type when position was ! // computed callback_T w_close_cb; // popup close callback callback_T w_filter_cb; // popup filter callback *** ../vim-8.1.1927/src/popupwin.c 2019-08-24 18:23:06.419390846 +0200 --- src/popupwin.c 2019-08-25 22:14:58.677912909 +0200 *************** *** 76,116 **** } static void - get_pos_options(win_T *wp, dict_T *dict) - { - char_u *str; - int nr; - dictitem_T *di; - - nr = popup_options_one(dict, (char_u *)"line"); - if (nr > 0) - wp->w_wantline = nr; - nr = popup_options_one(dict, (char_u *)"col"); - if (nr > 0) - wp->w_wantcol = nr; - - di = dict_find(dict, (char_u *)"fixed", -1); - if (di != NULL) - wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0; - - str = dict_get_string(dict, (char_u *)"pos", FALSE); - if (str != NULL) - { - for (nr = 0; - nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); - ++nr) - if (STRCMP(str, poppos_entries[nr].pp_name) == 0) - { - wp->w_popup_pos = poppos_entries[nr].pp_val; - nr = -1; - break; - } - if (nr != -1) - semsg(_(e_invarg2), str); - } - } - - static void set_padding_border(dict_T *dict, int *array, char *name, int max_val) { dictitem_T *di; --- 76,81 ---- *************** *** 256,262 **** { drag_start_row = mouse_row; drag_start_col = mouse_col; - // TODO: handle using different corner if (wp->w_wantline == 0) drag_start_wantline = wp->w_winrow + 1; else --- 221,226 ---- *************** *** 430,436 **** static void apply_move_options(win_T *wp, dict_T *d) { ! int nr; if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0) wp->w_minwidth = nr; --- 394,402 ---- static void apply_move_options(win_T *wp, dict_T *d) { ! int nr; ! char_u *str; ! dictitem_T *di; if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0) wp->w_minwidth = nr; *************** *** 440,446 **** wp->w_maxwidth = nr; if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) wp->w_maxheight = nr; ! get_pos_options(wp, d); } static void --- 406,469 ---- wp->w_maxwidth = nr; if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) wp->w_maxheight = nr; ! ! nr = popup_options_one(d, (char_u *)"line"); ! if (nr > 0) ! wp->w_wantline = nr; ! nr = popup_options_one(d, (char_u *)"col"); ! if (nr > 0) ! wp->w_wantcol = nr; ! ! di = dict_find(d, (char_u *)"fixed", -1); ! if (di != NULL) ! wp->w_popup_fixed = dict_get_number(d, (char_u *)"fixed") != 0; ! ! str = dict_get_string(d, (char_u *)"pos", FALSE); ! if (str != NULL) ! { ! for (nr = 0; ! nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); ! ++nr) ! if (STRCMP(str, poppos_entries[nr].pp_name) == 0) ! { ! wp->w_popup_pos = poppos_entries[nr].pp_val; ! nr = -1; ! break; ! } ! if (nr != -1) ! semsg(_(e_invarg2), str); ! } ! ! str = dict_get_string(d, (char_u *)"textprop", FALSE); ! if (str != NULL) ! { ! wp->w_popup_prop_type = 0; ! if (*str != NUL) ! { ! nr = find_prop_type_id(str, wp->w_buffer); ! if (nr <= 0) ! nr = find_prop_type_id(str, NULL); ! if (nr <= 0) ! semsg(_(e_invarg2), str); ! else ! { ! wp->w_popup_prop_type = nr; ! wp->w_popup_prop_win = curwin; ! ! di = dict_find(d, (char_u *)"textpropwin", -1); ! if (di != NULL) ! { ! wp->w_popup_prop_win = find_win_by_nr_or_id(&di->di_tv); ! if (win_valid(wp->w_popup_prop_win)) ! wp->w_popup_prop_win = curwin; ! } ! } ! } ! } ! ! di = dict_find(d, (char_u *)"textpropid", -1); ! if (di != NULL) ! wp->w_popup_prop_id = dict_get_number(d, (char_u *)"textpropid"); } static void *************** *** 1015,1026 **** --- 1038,1111 ---- int org_leftcol = wp->w_leftcol; int org_leftoff = wp->w_popup_leftoff; int minwidth; + int wantline = wp->w_wantline; // adjusted for textprop + int wantcol = wp->w_wantcol; // adjusted for textprop wp->w_winrow = 0; wp->w_wincol = 0; wp->w_leftcol = 0; wp->w_popup_leftoff = 0; wp->w_popup_rightoff = 0; + + // If no line was specified default to vertical centering. + if (wantline == 0) + center_vert = TRUE; + + if (wp->w_popup_prop_type > 0 && win_valid(wp->w_popup_prop_win)) + { + win_T *prop_win = wp->w_popup_prop_win; + textprop_T prop; + linenr_T prop_lnum; + pos_T pos; + int screen_row; + int screen_scol; + int screen_ccol; + int screen_ecol; + + // Popup window is positioned relative to a text property. + if (find_visible_prop(prop_win, + wp->w_popup_prop_type, wp->w_popup_prop_id, + &prop, &prop_lnum) == FAIL) + { + // Text property is no longer visible, hide the popup. + // Unhiding the popup is done in check_popup_unhidden(). + if ((wp->w_popup_flags & POPF_HIDDEN) == 0) + { + wp->w_popup_flags |= POPF_HIDDEN; + --wp->w_buffer->b_nwindows; + if (win_valid(wp->w_popup_prop_win)) + redraw_win_later(wp->w_popup_prop_win, SOME_VALID); + } + return; + } + + // Compute the desired position from the position of the text + // property. Use "wantline" and "wantcol" as offsets. + pos.lnum = prop_lnum; + pos.col = prop.tp_col; + if (wp->w_popup_pos == POPPOS_TOPLEFT + || wp->w_popup_pos == POPPOS_BOTLEFT) + pos.col += prop.tp_len - 1; + textpos2screenpos(prop_win, &pos, &screen_row, + &screen_scol, &screen_ccol, &screen_ecol); + + if (wp->w_popup_pos == POPPOS_TOPLEFT + || wp->w_popup_pos == POPPOS_TOPRIGHT) + // below the text + wantline = screen_row + wantline + 1; + else + // above the text + wantline = screen_row + wantline - 1; + center_vert = FALSE; + if (wp->w_popup_pos == POPPOS_TOPLEFT + || wp->w_popup_pos == POPPOS_BOTLEFT) + // right of the text + wantcol = screen_ecol + wantcol; + else + // left of the text + wantcol = screen_scol + wantcol - 1; + } + if (wp->w_popup_pos == POPPOS_CENTER) { // center after computing the size *************** *** 1029,1050 **** } else { ! if (wp->w_wantline == 0) ! center_vert = TRUE; ! else if (wp->w_popup_pos == POPPOS_TOPLEFT ! || wp->w_popup_pos == POPPOS_TOPRIGHT) { ! wp->w_winrow = wp->w_wantline - 1; if (wp->w_winrow >= Rows) wp->w_winrow = Rows - 1; } ! if (wp->w_wantcol == 0) center_hor = TRUE; else if (wp->w_popup_pos == POPPOS_TOPLEFT || wp->w_popup_pos == POPPOS_BOTLEFT) { ! wp->w_wincol = wp->w_wantcol - 1; if (wp->w_wincol >= Columns - 3) wp->w_wincol = Columns - 3; } --- 1114,1133 ---- } else { ! if (wantline != 0 && (wp->w_popup_pos == POPPOS_TOPLEFT ! || wp->w_popup_pos == POPPOS_TOPRIGHT)) { ! wp->w_winrow = wantline - 1; if (wp->w_winrow >= Rows) wp->w_winrow = Rows - 1; } ! if (wantcol == 0) center_hor = TRUE; else if (wp->w_popup_pos == POPPOS_TOPLEFT || wp->w_popup_pos == POPPOS_BOTLEFT) { ! wp->w_wincol = wantcol - 1; if (wp->w_wincol >= Columns - 3) wp->w_wincol = Columns - 3; } *************** *** 1161,1167 **** else if (wp->w_popup_pos == POPPOS_BOTRIGHT || wp->w_popup_pos == POPPOS_TOPRIGHT) { ! int leftoff = wp->w_wantcol - (wp->w_width + extra_width); // Right aligned: move to the right if needed. // No truncation, because that would change the height. --- 1244,1250 ---- else if (wp->w_popup_pos == POPPOS_BOTRIGHT || wp->w_popup_pos == POPPOS_TOPRIGHT) { ! int leftoff = wantcol - (wp->w_width + extra_width); // Right aligned: move to the right if needed. // No truncation, because that would change the height. *************** *** 1216,1230 **** else if (wp->w_popup_pos == POPPOS_BOTRIGHT || wp->w_popup_pos == POPPOS_BOTLEFT) { ! if ((wp->w_height + extra_height) <= wp->w_wantline) // bottom aligned: may move down ! wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height); else // not enough space, make top aligned ! wp->w_winrow = wp->w_wantline + 1; } wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); // Need to update popup_mask if the position or size changed. // And redraw windows and statuslines that were behind the popup. --- 1299,1323 ---- else if (wp->w_popup_pos == POPPOS_BOTRIGHT || wp->w_popup_pos == POPPOS_BOTLEFT) { ! if ((wp->w_height + extra_height) <= wantline) // bottom aligned: may move down ! wp->w_winrow = wantline - (wp->w_height + extra_height); else // not enough space, make top aligned ! wp->w_winrow = wantline + 1; } + if (wp->w_winrow >= Rows) + wp->w_winrow = Rows - 1; + else if (wp->w_winrow < 0) + wp->w_winrow = 0; wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); + if (win_valid(wp->w_popup_prop_win)) + { + wp->w_popup_prop_changedtick = + CHANGEDTICK(wp->w_popup_prop_win->w_buffer); + wp->w_popup_prop_topline = wp->w_popup_prop_win->w_topline; + } // Need to update popup_mask if the position or size changed. // And redraw windows and statuslines that were behind the popup. *************** *** 1837,1853 **** popup_close(id); } /* * Close popup "wp" because of a mouse click. */ void popup_close_for_mouse_click(win_T *wp) { ! typval_T res; ! ! res.v_type = VAR_NUMBER; ! res.vval.v_number = -2; ! popup_close_and_callback(wp, &res); } static void --- 1930,1952 ---- popup_close(id); } + static void + popup_close_with_retval(win_T *wp, int retval) + { + typval_T res; + + res.v_type = VAR_NUMBER; + res.vval.v_number = retval; + popup_close_and_callback(wp, &res); + } + /* * Close popup "wp" because of a mouse click. */ void popup_close_for_mouse_click(win_T *wp) { ! popup_close_with_retval(wp, -2); } static void *************** *** 1864,1875 **** || mouse_col < wp->w_popup_mouse_mincol || mouse_col > wp->w_popup_mouse_maxcol)) { - typval_T res; - - res.v_type = VAR_NUMBER; - res.vval.v_number = -2; // Careful: this makes "wp" invalid. ! popup_close_and_callback(wp, &res); } } --- 1963,1970 ---- || mouse_col < wp->w_popup_mouse_mincol || mouse_col > wp->w_popup_mouse_maxcol)) { // Careful: this makes "wp" invalid. ! popup_close_with_retval(wp, -2); } } *************** *** 2458,2467 **** dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); dict_add_number(dict, "zindex", wp->w_zindex); dict_add_number(dict, "fixed", wp->w_popup_fixed); dict_add_string(dict, "title", wp->w_popup_title); dict_add_number(dict, "wrap", wp->w_p_wrap); dict_add_number(dict, "drag", (wp->w_popup_flags & POPF_DRAG) != 0); ! dict_add_number(dict, "mapping", (wp->w_popup_flags & POPF_MAPPING) != 0); dict_add_number(dict, "resize", (wp->w_popup_flags & POPF_RESIZE) != 0); dict_add_number(dict, "cursorline", (wp->w_popup_flags & POPF_CURSORLINE) != 0); --- 2553,2574 ---- dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); dict_add_number(dict, "zindex", wp->w_zindex); dict_add_number(dict, "fixed", wp->w_popup_fixed); + if (wp->w_popup_prop_type && win_valid(wp->w_popup_prop_win)) + { + proptype_T *pt = text_prop_type_by_id( + wp->w_popup_prop_win->w_buffer, + wp->w_popup_prop_type); + + if (pt != NULL) + dict_add_string(dict, "textprop", pt->pt_name); + dict_add_number(dict, "textpropwin", wp->w_popup_prop_win->w_id); + dict_add_number(dict, "textpropid", wp->w_popup_prop_id); + } dict_add_string(dict, "title", wp->w_popup_title); dict_add_number(dict, "wrap", wp->w_p_wrap); dict_add_number(dict, "drag", (wp->w_popup_flags & POPF_DRAG) != 0); ! dict_add_number(dict, "mapping", ! (wp->w_popup_flags & POPF_MAPPING) != 0); dict_add_number(dict, "resize", (wp->w_popup_flags & POPF_RESIZE) != 0); dict_add_number(dict, "cursorline", (wp->w_popup_flags & POPF_CURSORLINE) != 0); *************** *** 2603,2611 **** // Emergency exit: CTRL-C closes the popup. if (c == Ctrl_C) { ! rettv.v_type = VAR_NUMBER; ! rettv.vval.v_number = -1; ! popup_close_and_callback(wp, &rettv); return 1; } --- 2710,2716 ---- // Emergency exit: CTRL-C closes the popup. if (c == Ctrl_C) { ! popup_close_with_retval(wp, -1); return 1; } *************** *** 2687,2693 **** popup_check_cursor_pos() { win_T *wp; - typval_T tv; popup_reset_handled(); while ((wp = find_next_popup(TRUE)) != NULL) --- 2792,2797 ---- *************** *** 2696,2706 **** || curwin->w_cursor.lnum != wp->w_popup_lnum || curwin->w_cursor.col < wp->w_popup_mincol || curwin->w_cursor.col > wp->w_popup_maxcol)) ! { ! tv.v_type = VAR_NUMBER; ! tv.vval.v_number = -1; ! popup_close_and_callback(wp, &tv); ! } } /* --- 2800,2806 ---- || curwin->w_cursor.lnum != wp->w_popup_lnum || curwin->w_cursor.col < wp->w_popup_mincol || curwin->w_cursor.col > wp->w_popup_maxcol)) ! popup_close_with_retval(wp, -1); } /* *************** *** 2822,2827 **** --- 2922,2972 ---- } /* + * Only called when popup window "wp" is hidden: If the window is positioned + * next to a text property, and it is now visible, then unhide the popup. + * We don't check if visible popups become hidden, that is done in + * popup_adjust_position(). + * Return TRUE if the popup became unhidden. + */ + static int + check_popup_unhidden(win_T *wp) + { + if (wp->w_popup_prop_type > 0 && win_valid(wp->w_popup_prop_win)) + { + textprop_T prop; + linenr_T lnum; + + if (find_visible_prop(wp->w_popup_prop_win, + wp->w_popup_prop_type, wp->w_popup_prop_id, + &prop, &lnum) == OK) + { + wp->w_popup_flags &= ~POPF_HIDDEN; + ++wp->w_buffer->b_nwindows; + wp->w_popup_prop_topline = 0; // force repositioning + return TRUE; + } + } + return FALSE; + } + + /* + * Return TRUE if popup_adjust_position() needs to be called for "wp". + * That is when the buffer in the popup was changed, or the popup is following + * a textprop and the referenced buffer was changed. + */ + static int + popup_need_position_adjust(win_T *wp) + { + if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) + return TRUE; + if (win_valid(wp->w_popup_prop_win)) + return wp->w_popup_prop_changedtick + != CHANGEDTICK(wp->w_popup_prop_win->w_buffer) + || wp->w_popup_prop_topline != wp->w_popup_prop_win->w_topline; + return FALSE; + } + + /* * Update "popup_mask" if needed. * Also recomputes the popup size and positions. * Also updates "popup_visible". *************** *** 2844,2861 **** popup_mask_refresh = TRUE; redraw_all_popups = TRUE; } if (!popup_mask_refresh) ! { ! // Check if any popup window buffer has changed. ! for (wp = first_popupwin; wp != NULL; wp = wp->w_next) ! if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) ! popup_mask_refresh = TRUE; ! for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) ! if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) ! popup_mask_refresh = TRUE; ! if (!popup_mask_refresh) ! return; ! } // Need to update the mask, something has changed. popup_mask_refresh = FALSE; --- 2989,3010 ---- popup_mask_refresh = TRUE; redraw_all_popups = TRUE; } + + // Check if any popup window buffer has changed and if any popup connected + // to a text property has become visible. + for (wp = first_popupwin; wp != NULL; wp = wp->w_next) + if (wp->w_popup_flags & POPF_HIDDEN) + popup_mask_refresh |= check_popup_unhidden(wp); + else if (popup_need_position_adjust(wp)) + popup_mask_refresh = TRUE; + for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) + if (wp->w_popup_flags & POPF_HIDDEN) + popup_mask_refresh |= check_popup_unhidden(wp); + else if (popup_need_position_adjust(wp)) + popup_mask_refresh = TRUE; + if (!popup_mask_refresh) ! return; // Need to update the mask, something has changed. popup_mask_refresh = FALSE; *************** *** 2886,2895 **** popup_visible = TRUE; ! // Recompute the position if the text changed. ! if (redraw_all_popups ! || wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) popup_adjust_position(wp); width = popup_width(wp); height = popup_height(wp); --- 3035,3048 ---- popup_visible = TRUE; ! // Recompute the position if the text changed. It may make the popup ! // hidden if it's attach to a text property that is no longer visible. ! if (redraw_all_popups || popup_need_position_adjust(wp)) ! { popup_adjust_position(wp); + if (wp->w_popup_flags & POPF_HIDDEN) + continue; + } width = popup_width(wp); height = popup_height(wp); *************** *** 3411,3423 **** win_T *wp = popup_find_preview_window(); if (wp != NULL) ! { ! typval_T res; ! ! res.v_type = VAR_NUMBER; ! res.vval.v_number = -1; ! popup_close_and_callback(wp, &res); ! } } /* --- 3564,3570 ---- win_T *wp = popup_find_preview_window(); if (wp != NULL) ! popup_close_with_retval(wp, -1); } /* *************** *** 3434,3439 **** --- 3581,3610 ---- #endif /* + * Close any popup for a text property associated with "win". + * Return TRUE if a popup was closed. + */ + int + popup_win_closed(win_T *win) + { + win_T *wp; + + for (wp = first_popupwin; wp != NULL; wp = wp->w_next) + if (wp->w_popup_prop_win == win) + { + popup_close_with_retval(wp, -1); + return TRUE; + } + for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) + if (wp->w_popup_prop_win == win) + { + popup_close_with_retval(wp, -1); + return TRUE; + } + return FALSE; + } + + /* * Set the title of the popup window to the file name. */ void *** ../vim-8.1.1927/src/proto/popupwin.pro 2019-08-24 18:23:06.419390846 +0200 --- src/proto/popupwin.pro 2019-08-25 21:55:29.562568756 +0200 *************** *** 55,60 **** --- 55,61 ---- int popup_create_preview_window(int info); void popup_close_preview(void); void popup_hide_info(void); + int popup_win_closed(win_T *win); void popup_set_title(win_T *wp); void popup_update_preview_title(void); /* vim: set ft=c : */ *** ../vim-8.1.1927/src/move.c 2019-08-21 14:36:29.391376081 +0200 --- src/move.c 2019-08-25 21:33:02.488203727 +0200 *************** *** 1179,1190 **** curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; } ! #if defined(FEAT_EVAL) || defined(PROTO) /* * Compute the screen position of text character at "pos" in window "wp" * The resulting values are one-based, zero when character is not visible. */ ! static void textpos2screenpos( win_T *wp, pos_T *pos, --- 1179,1190 ---- curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; } ! #if (defined(FEAT_EVAL) || defined(FEAT_TEXT_PROP)) || defined(PROTO) /* * Compute the screen position of text character at "pos" in window "wp" * The resulting values are one-based, zero when character is not visible. */ ! void textpos2screenpos( win_T *wp, pos_T *pos, *************** *** 1213,1224 **** col += off; width = wp->w_width - off + win_col_off2(wp); ! /* long line wrapping, adjust row */ if (wp->w_p_wrap && col >= (colnr_T)wp->w_width && width > 0) { ! /* use same formula as what is used in curs_columns() */ rowoff = ((col - wp->w_width) / width + 1); col -= rowoff * width; } --- 1213,1224 ---- col += off; width = wp->w_width - off + win_col_off2(wp); ! // long line wrapping, adjust row if (wp->w_p_wrap && col >= (colnr_T)wp->w_width && width > 0) { ! // use same formula as what is used in curs_columns() rowoff = ((col - wp->w_width) / width + 1); col -= rowoff * width; } *************** *** 1236,1242 **** --- 1236,1244 ---- *ccolp = ccol + coloff; *ecolp = ecol + coloff; } + #endif + #if defined(FEAT_EVAL) || defined(PROTO) /* * "screenpos({winid}, {lnum}, {col})" function */ *** ../vim-8.1.1927/src/proto/move.pro 2019-07-07 18:27:52.365277132 +0200 --- src/proto/move.pro 2019-08-25 21:33:11.056166078 +0200 *************** *** 27,32 **** --- 27,33 ---- int win_col_off2(win_T *wp); int curwin_col_off2(void); void curs_columns(int may_scroll); + void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp, int *ecolp); void f_screenpos(typval_T *argvars, typval_T *rettv); void scrolldown(long line_count, int byfold); void scrollup(long line_count, int byfold); *** ../vim-8.1.1927/src/window.c 2019-08-21 22:25:26.030016778 +0200 --- src/window.c 2019-08-25 21:53:41.742933425 +0200 *************** *** 2522,2527 **** --- 2522,2531 ---- out_flush(); #endif + #ifdef FEAT_TEXT_PROP + if (popup_win_closed(win) && !win_valid(win)) + return FAIL; + #endif win_close_buffer(win, free_buf ? DOBUF_UNLOAD : 0, TRUE); if (only_one_window() && win_valid(win) && win->w_buffer == NULL *** ../vim-8.1.1927/src/version.c 2019-08-25 15:40:39.662739502 +0200 --- src/version.c 2019-08-25 16:00:31.264415745 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1928, /**/ -- hundred-and-one symptoms of being an internet addict: 118. You are on a first-name basis with your ISP's staff. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///