Mercurial > vim
comparison src/popupwin.c @ 17551:8cca2654d459 v8.1.1773
patch 8.1.1773: the preview popup window may be too far to the right
commit https://github.com/vim/vim/commit/13d5c3f6162694a7e925e66fc4eea35436643384
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 28 21:42:38 2019 +0200
patch 8.1.1773: the preview popup window may be too far to the right
Problem: The preview popup window may be too far to the right.
Solution: Keep it inside the screen. Also keep the close button and
scrollbar visible if possible.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Jul 2019 21:45:05 +0200 |
parents | 1e45331bd2ab |
children | 724370d05e79 |
comparison
equal
deleted
inserted
replaced
17550:9afddb85a45c | 17551:8cca2654d459 |
---|---|
1024 break; | 1024 break; |
1025 } | 1025 } |
1026 | 1026 |
1027 wp->w_has_scrollbar = wp->w_want_scrollbar | 1027 wp->w_has_scrollbar = wp->w_want_scrollbar |
1028 && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); | 1028 && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); |
1029 if (wp->w_has_scrollbar) | |
1030 ++right_extra; | |
1029 | 1031 |
1030 minwidth = wp->w_minwidth; | 1032 minwidth = wp->w_minwidth; |
1031 if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) | 1033 if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
1032 { | 1034 { |
1033 int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; | 1035 int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; |
1038 | 1040 |
1039 if (minwidth > 0 && wp->w_width < minwidth) | 1041 if (minwidth > 0 && wp->w_width < minwidth) |
1040 wp->w_width = minwidth; | 1042 wp->w_width = minwidth; |
1041 if (wp->w_width > maxwidth) | 1043 if (wp->w_width > maxwidth) |
1042 { | 1044 { |
1043 if (wp->w_width > maxspace) | 1045 if (wp->w_width > maxspace && !wp->w_p_wrap) |
1044 // some columns cut off on the right | 1046 // some columns cut off on the right |
1045 wp->w_popup_rightoff = wp->w_width - maxspace; | 1047 wp->w_popup_rightoff = wp->w_width - maxspace; |
1046 wp->w_width = maxwidth; | 1048 wp->w_width = maxwidth; |
1047 } | 1049 } |
1048 if (center_hor) | 1050 if (center_hor) |
1072 if (wp->w_width < 0) | 1074 if (wp->w_width < 0) |
1073 wp->w_width = 0; | 1075 wp->w_width = 0; |
1074 } | 1076 } |
1075 } | 1077 } |
1076 | 1078 |
1079 if (wp->w_p_wrap) | |
1080 { | |
1081 int want_col = 0; | |
1082 | |
1083 if (wp->w_popup_close == POPCLOSE_BUTTON) | |
1084 // try to show the close button | |
1085 want_col = left_extra + wp->w_width + right_extra; | |
1086 else if (wp->w_has_scrollbar) | |
1087 // try to show the scrollbar | |
1088 want_col = left_extra + wp->w_width | |
1089 + right_extra - wp->w_popup_border[1]; | |
1090 if (want_col > 0 && wp->w_wincol > 0 | |
1091 && wp->w_wincol + want_col >= Columns) | |
1092 { | |
1093 wp->w_wincol = Columns - want_col; | |
1094 if (wp->w_wincol < 0) | |
1095 wp->w_wincol = 0; | |
1096 } | |
1097 } | |
1098 | |
1077 wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline | 1099 wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline |
1078 + 1 + wrapped; | 1100 + 1 + wrapped; |
1079 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) | 1101 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) |
1080 wp->w_height = wp->w_minheight; | 1102 wp->w_height = wp->w_minheight; |
1081 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) | 1103 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) |
1110 || org_leftoff != wp->w_popup_leftoff | 1132 || org_leftoff != wp->w_popup_leftoff |
1111 || org_width != wp->w_width | 1133 || org_width != wp->w_width |
1112 || org_height != wp->w_height) | 1134 || org_height != wp->w_height) |
1113 { | 1135 { |
1114 redraw_all_later(VALID); | 1136 redraw_all_later(VALID); |
1137 redraw_win_later(wp, NOT_VALID); | |
1138 if (wp->w_popup_flags & POPF_ON_CMDLINE) | |
1139 clear_cmdline = TRUE; | |
1115 popup_mask_refresh = TRUE; | 1140 popup_mask_refresh = TRUE; |
1116 } | 1141 } |
1117 } | 1142 } |
1118 | 1143 |
1119 typedef enum | 1144 typedef enum |
1219 return OK; | 1244 return OK; |
1220 } | 1245 } |
1221 | 1246 |
1222 /* | 1247 /* |
1223 * Set w_wantline and w_wantcol for the cursor position in the current window. | 1248 * Set w_wantline and w_wantcol for the cursor position in the current window. |
1224 */ | 1249 * Keep at least "width" columns from the right of the screen. |
1225 void | 1250 */ |
1226 popup_set_wantpos(win_T *wp) | 1251 void |
1252 popup_set_wantpos(win_T *wp, int width) | |
1227 { | 1253 { |
1228 setcursor_mayforce(TRUE); | 1254 setcursor_mayforce(TRUE); |
1229 wp->w_wantline = curwin->w_winrow + curwin->w_wrow; | 1255 wp->w_wantline = curwin->w_winrow + curwin->w_wrow; |
1230 if (wp->w_wantline == 0) // cursor in first line | 1256 if (wp->w_wantline == 0) // cursor in first line |
1231 { | 1257 { |
1232 wp->w_wantline = 2; | 1258 wp->w_wantline = 2; |
1233 wp->w_popup_pos = POPPOS_TOPLEFT; | 1259 wp->w_popup_pos = POPPOS_TOPLEFT; |
1234 } | 1260 } |
1261 | |
1235 wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1; | 1262 wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1; |
1263 if (wp->w_wantcol > Columns - width) | |
1264 { | |
1265 wp->w_wantcol = Columns - width; | |
1266 if (wp->w_wantcol < 1) | |
1267 wp->w_wantcol = 1; | |
1268 } | |
1236 popup_adjust_position(wp); | 1269 popup_adjust_position(wp); |
1237 } | 1270 } |
1238 | 1271 |
1239 /* | 1272 /* |
1240 * popup_create({text}, {options}) | 1273 * popup_create({text}, {options}) |
1376 popup_set_buffer_text(buf, argvars[0]); | 1409 popup_set_buffer_text(buf, argvars[0]); |
1377 | 1410 |
1378 if (type == TYPE_ATCURSOR || type == TYPE_PREVIEW) | 1411 if (type == TYPE_ATCURSOR || type == TYPE_PREVIEW) |
1379 { | 1412 { |
1380 wp->w_popup_pos = POPPOS_BOTLEFT; | 1413 wp->w_popup_pos = POPPOS_BOTLEFT; |
1381 popup_set_wantpos(wp); | |
1382 } | 1414 } |
1383 if (type == TYPE_ATCURSOR) | 1415 if (type == TYPE_ATCURSOR) |
1384 { | 1416 { |
1417 popup_set_wantpos(wp, 0); | |
1385 set_moved_values(wp); | 1418 set_moved_values(wp); |
1386 set_moved_columns(wp, FIND_STRING); | 1419 set_moved_columns(wp, FIND_STRING); |
1387 } | 1420 } |
1388 | 1421 |
1389 if (type == TYPE_BEVAL) | 1422 if (type == TYPE_BEVAL) |
1483 wp->w_popup_drag = 1; | 1516 wp->w_popup_drag = 1; |
1484 wp->w_popup_close = POPCLOSE_BUTTON; | 1517 wp->w_popup_close = POPCLOSE_BUTTON; |
1485 for (i = 0; i < 4; ++i) | 1518 for (i = 0; i < 4; ++i) |
1486 wp->w_popup_border[i] = 1; | 1519 wp->w_popup_border[i] = 1; |
1487 parse_previewpopup(wp); | 1520 parse_previewpopup(wp); |
1521 popup_set_wantpos(wp, wp->w_minwidth); | |
1488 } | 1522 } |
1489 | 1523 |
1490 for (i = 0; i < 4; ++i) | 1524 for (i = 0; i < 4; ++i) |
1491 VIM_CLEAR(wp->w_border_highlight[i]); | 1525 VIM_CLEAR(wp->w_border_highlight[i]); |
1492 for (i = 0; i < 8; ++i) | 1526 for (i = 0; i < 8; ++i) |
1876 if (argvars[1].v_type != VAR_STRING && argvars[1].v_type != VAR_LIST) | 1910 if (argvars[1].v_type != VAR_STRING && argvars[1].v_type != VAR_LIST) |
1877 semsg(_(e_invarg2), tv_get_string(&argvars[1])); | 1911 semsg(_(e_invarg2), tv_get_string(&argvars[1])); |
1878 else | 1912 else |
1879 { | 1913 { |
1880 popup_set_buffer_text(wp->w_buffer, argvars[1]); | 1914 popup_set_buffer_text(wp->w_buffer, argvars[1]); |
1915 redraw_win_later(wp, NOT_VALID); | |
1881 popup_adjust_position(wp); | 1916 popup_adjust_position(wp); |
1882 } | 1917 } |
1883 } | 1918 } |
1884 } | 1919 } |
1885 | 1920 |
1886 static void | 1921 static void |
1887 popup_free(win_T *wp) | 1922 popup_free(win_T *wp) |
1888 { | 1923 { |
1889 sign_undefine_by_name(popup_get_sign_name(wp), FALSE); | 1924 sign_undefine_by_name(popup_get_sign_name(wp), FALSE); |
1890 wp->w_buffer->b_locked = FALSE; | 1925 wp->w_buffer->b_locked = FALSE; |
1891 if (wp->w_winrow + wp->w_height >= cmdline_row) | 1926 if (wp->w_winrow + popup_height(wp) >= cmdline_row) |
1892 clear_cmdline = TRUE; | 1927 clear_cmdline = TRUE; |
1893 win_free_popup(wp); | 1928 win_free_popup(wp); |
1894 | 1929 |
1895 redraw_all_later(NOT_VALID); | 1930 redraw_all_later(NOT_VALID); |
1896 popup_mask_refresh = TRUE; | 1931 popup_mask_refresh = TRUE; |
2754 | 2789 |
2755 total_width = popup_width(wp); | 2790 total_width = popup_width(wp); |
2756 total_height = popup_height(wp); | 2791 total_height = popup_height(wp); |
2757 popup_attr = get_wcr_attr(wp); | 2792 popup_attr = get_wcr_attr(wp); |
2758 | 2793 |
2794 if (wp->w_winrow + total_height > cmdline_row) | |
2795 wp->w_popup_flags |= POPF_ON_CMDLINE; | |
2796 else | |
2797 wp->w_popup_flags &= ~POPF_ON_CMDLINE; | |
2798 | |
2799 | |
2759 // We can only use these line drawing characters when 'encoding' is | 2800 // We can only use these line drawing characters when 'encoding' is |
2760 // "utf-8" and 'ambiwidth' is "single". | 2801 // "utf-8" and 'ambiwidth' is "single". |
2761 if (enc_utf8 && *p_ambw == 's') | 2802 if (enc_utf8 && *p_ambw == 's') |
2762 { | 2803 { |
2763 border_char[0] = border_char[2] = 0x2550; | 2804 border_char[0] = border_char[2] = 0x2550; |