Mercurial > vim
comparison src/popupwin.c @ 17180:8581779aa16f v8.1.1589
patch 8.1.1589: popup window does not indicate scroll position
commit https://github.com/vim/vim/commit/75fb0854e93913c4d2cfcd6ef634173c4d13a093
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 25 05:15:58 2019 +0200
patch 8.1.1589: popup window does not indicate scroll position
Problem: Popup window does not indicate scroll position.
Solution: Add a scrollbar.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 25 Jun 2019 05:30:06 +0200 |
parents | 23609a6d8cc7 |
children | f4c6c1bc5e41 |
comparison
equal
deleted
inserted
replaced
17179:9c7fd1b6445b | 17180:8581779aa16f |
---|---|
284 di = dict_find(dict, (char_u *)"firstline", -1); | 284 di = dict_find(dict, (char_u *)"firstline", -1); |
285 if (di != NULL) | 285 if (di != NULL) |
286 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); | 286 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); |
287 if (wp->w_firstline < 1) | 287 if (wp->w_firstline < 1) |
288 wp->w_firstline = 1; | 288 wp->w_firstline = 1; |
289 | |
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"); | |
289 | 293 |
290 str = dict_get_string(dict, (char_u *)"title", FALSE); | 294 str = dict_get_string(dict, (char_u *)"title", FALSE); |
291 if (str != NULL) | 295 if (str != NULL) |
292 { | 296 { |
293 vim_free(wp->w_popup_title); | 297 vim_free(wp->w_popup_title); |
731 if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count | 735 if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count |
732 - wp->w_topline + 1 + wrapped > wp->w_maxheight) | 736 - wp->w_topline + 1 + wrapped > wp->w_maxheight) |
733 break; | 737 break; |
734 } | 738 } |
735 | 739 |
740 wp->w_has_scrollbar = wp->w_want_scrollbar | |
741 && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); | |
742 | |
736 minwidth = wp->w_minwidth; | 743 minwidth = wp->w_minwidth; |
737 if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) | 744 if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
738 { | 745 { |
739 int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; | 746 int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; |
740 | 747 |
1045 | 1052 |
1046 for (i = 0; i < 4; ++i) | 1053 for (i = 0; i < 4; ++i) |
1047 VIM_CLEAR(wp->w_border_highlight[i]); | 1054 VIM_CLEAR(wp->w_border_highlight[i]); |
1048 for (i = 0; i < 8; ++i) | 1055 for (i = 0; i < 8; ++i) |
1049 wp->w_border_char[i] = 0; | 1056 wp->w_border_char[i] = 0; |
1057 wp->w_want_scrollbar = 1; | |
1050 | 1058 |
1051 // Deal with options. | 1059 // Deal with options. |
1052 apply_options(wp, argvars[1].vval.v_dict); | 1060 apply_options(wp, argvars[1].vval.v_dict); |
1053 | 1061 |
1054 #ifdef FEAT_TIMERS | 1062 #ifdef FEAT_TIMERS |
1481 f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) | 1489 f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) |
1482 { | 1490 { |
1483 dict_T *dict; | 1491 dict_T *dict; |
1484 int id = (int)tv_get_number(argvars); | 1492 int id = (int)tv_get_number(argvars); |
1485 win_T *wp = find_popup_win(id); | 1493 win_T *wp = find_popup_win(id); |
1494 linenr_T old_firstline; | |
1486 | 1495 |
1487 if (wp == NULL) | 1496 if (wp == NULL) |
1488 return; // invalid {id} | 1497 return; // invalid {id} |
1489 | 1498 |
1490 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) | 1499 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
1491 { | 1500 { |
1492 emsg(_(e_dictreq)); | 1501 emsg(_(e_dictreq)); |
1493 return; | 1502 return; |
1494 } | 1503 } |
1495 dict = argvars[1].vval.v_dict; | 1504 dict = argvars[1].vval.v_dict; |
1505 old_firstline = wp->w_firstline; | |
1496 | 1506 |
1497 apply_move_options(wp, dict); | 1507 apply_move_options(wp, dict); |
1498 apply_general_options(wp, dict); | 1508 apply_general_options(wp, dict); |
1499 | 1509 |
1510 if (old_firstline != wp->w_firstline) | |
1511 redraw_win_later(wp, NOT_VALID); | |
1500 popup_mask_refresh = TRUE; | 1512 popup_mask_refresh = TRUE; |
1501 popup_adjust_position(wp); | 1513 popup_adjust_position(wp); |
1502 } | 1514 } |
1503 | 1515 |
1504 /* | 1516 /* |
1532 dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra); | 1544 dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra); |
1533 dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra); | 1545 dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra); |
1534 dict_add_number(dict, "core_width", wp->w_width); | 1546 dict_add_number(dict, "core_width", wp->w_width); |
1535 dict_add_number(dict, "core_height", wp->w_height); | 1547 dict_add_number(dict, "core_height", wp->w_height); |
1536 | 1548 |
1549 dict_add_number(dict, "scrollbar", wp->w_has_scrollbar); | |
1537 dict_add_number(dict, "visible", | 1550 dict_add_number(dict, "visible", |
1538 win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0); | 1551 win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0); |
1539 } | 1552 } |
1540 } | 1553 } |
1541 | 1554 |
1654 dict_add_number(dict, "minwidth", wp->w_minwidth); | 1667 dict_add_number(dict, "minwidth", wp->w_minwidth); |
1655 dict_add_number(dict, "minheight", wp->w_minheight); | 1668 dict_add_number(dict, "minheight", wp->w_minheight); |
1656 dict_add_number(dict, "maxheight", wp->w_maxheight); | 1669 dict_add_number(dict, "maxheight", wp->w_maxheight); |
1657 dict_add_number(dict, "maxwidth", wp->w_maxwidth); | 1670 dict_add_number(dict, "maxwidth", wp->w_maxwidth); |
1658 dict_add_number(dict, "firstline", wp->w_firstline); | 1671 dict_add_number(dict, "firstline", wp->w_firstline); |
1672 dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); | |
1659 dict_add_number(dict, "zindex", wp->w_zindex); | 1673 dict_add_number(dict, "zindex", wp->w_zindex); |
1660 dict_add_number(dict, "fixed", wp->w_popup_fixed); | 1674 dict_add_number(dict, "fixed", wp->w_popup_fixed); |
1661 dict_add_string(dict, "title", wp->w_popup_title); | 1675 dict_add_string(dict, "title", wp->w_popup_title); |
1662 dict_add_number(dict, "wrap", wp->w_p_wrap); | 1676 dict_add_number(dict, "wrap", wp->w_p_wrap); |
1663 dict_add_number(dict, "drag", wp->w_popup_drag); | 1677 dict_add_number(dict, "drag", wp->w_popup_drag); |
2112 int border_attr[4]; | 2126 int border_attr[4]; |
2113 int border_char[8]; | 2127 int border_char[8]; |
2114 char_u buf[MB_MAXBYTES]; | 2128 char_u buf[MB_MAXBYTES]; |
2115 int row; | 2129 int row; |
2116 int i; | 2130 int i; |
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]; | |
2117 | 2135 |
2118 // Find the window with the lowest zindex that hasn't been updated yet, | 2136 // Find the window with the lowest zindex that hasn't been updated yet, |
2119 // so that the window with a higher zindex is drawn later, thus goes on | 2137 // so that the window with a higher zindex is drawn later, thus goes on |
2120 // top. | 2138 // top. |
2121 popup_reset_handled(); | 2139 popup_reset_handled(); |
2141 | 2159 |
2142 wp->w_winrow -= top_off; | 2160 wp->w_winrow -= top_off; |
2143 wp->w_wincol -= left_off; | 2161 wp->w_wincol -= left_off; |
2144 | 2162 |
2145 total_width = wp->w_popup_border[3] + wp->w_popup_padding[3] | 2163 total_width = wp->w_popup_border[3] + wp->w_popup_padding[3] |
2146 + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1]; | 2164 + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1] |
2165 + wp->w_has_scrollbar; | |
2147 total_height = popup_top_extra(wp) | 2166 total_height = popup_top_extra(wp) |
2148 + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2]; | 2167 + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
2149 popup_attr = get_wcr_attr(wp); | 2168 popup_attr = get_wcr_attr(wp); |
2150 | 2169 |
2151 // We can only use these line drawing characters when 'encoding' is | 2170 // We can only use these line drawing characters when 'encoding' is |
2201 { | 2220 { |
2202 // top padding | 2221 // top padding |
2203 row = wp->w_winrow + wp->w_popup_border[0]; | 2222 row = wp->w_winrow + wp->w_popup_border[0]; |
2204 screen_fill(row, row + top_padding, | 2223 screen_fill(row, row + top_padding, |
2205 wp->w_wincol + wp->w_popup_border[3], | 2224 wp->w_wincol + wp->w_popup_border[3], |
2206 wp->w_wincol + total_width - wp->w_popup_border[1], | 2225 wp->w_wincol + total_width - wp->w_popup_border[1] |
2226 - wp->w_has_scrollbar, | |
2207 ' ', ' ', popup_attr); | 2227 ' ', ' ', popup_attr); |
2208 } | 2228 } |
2209 | 2229 |
2210 // Title goes on top of border or padding. | 2230 // Title goes on top of border or padding. |
2211 if (wp->w_popup_title != NULL) | 2231 if (wp->w_popup_title != NULL) |
2212 screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1, | 2232 screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1, |
2213 wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr); | 2233 wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr); |
2214 | 2234 |
2215 for (row = wp->w_winrow + wp->w_popup_border[0]; | 2235 // Compute scrollbar thumb position and size. |
2216 row < wp->w_winrow + total_height - wp->w_popup_border[2]; | 2236 if (wp->w_has_scrollbar) |
2217 ++row) | 2237 { |
2218 { | 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 | |
2219 // left border | 2253 // left border |
2220 if (wp->w_popup_border[3] > 0) | 2254 if (wp->w_popup_border[3] > 0) |
2221 { | 2255 { |
2222 buf[mb_char2bytes(border_char[3], buf)] = NUL; | 2256 buf[mb_char2bytes(border_char[3], buf)] = NUL; |
2223 screen_puts(buf, row, wp->w_wincol, border_attr[3]); | 2257 screen_puts(buf, row, wp->w_wincol, border_attr[3]); |
2224 } | 2258 } |
2225 // left padding | 2259 // left padding |
2226 if (wp->w_popup_padding[3] > 0) | 2260 if (wp->w_popup_padding[3] > 0) |
2227 screen_puts(get_spaces(wp->w_popup_padding[3]), row, | 2261 screen_puts(get_spaces(wp->w_popup_padding[3]), row, |
2228 wp->w_wincol + wp->w_popup_border[3], popup_attr); | 2262 wp->w_wincol + wp->w_popup_border[3], popup_attr); |
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 } | |
2229 // right border | 2278 // right border |
2230 if (wp->w_popup_border[1] > 0) | 2279 if (wp->w_popup_border[1] > 0) |
2231 { | 2280 { |
2232 buf[mb_char2bytes(border_char[1], buf)] = NUL; | 2281 buf[mb_char2bytes(border_char[1], buf)] = NUL; |
2233 screen_puts(buf, row, | 2282 screen_puts(buf, row, |