comparison src/popupwin.c @ 17905:fb773f73a4be v8.1.1949

patch 8.1.1949: cannot scroll a popup window to the very bottom Commit: https://github.com/vim/vim/commit/8c6173c7d3431dd8bc2b6ffc076ef49512a7e175 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 30 22:08:34 2019 +0200 patch 8.1.1949: cannot scroll a popup window to the very bottom Problem: Cannot scroll a popup window to the very bottom. Solution: Scroll to the bottom when the "firstline" property was set to -1. (closes #4577) Allow resetting min/max width/height.
author Bram Moolenaar <Bram@vim.org>
date Fri, 30 Aug 2019 22:15:04 +0200
parents fa032e079825
children ad7a4bd65f20
comparison
equal deleted inserted replaced
17904:d3e61b35a3b6 17905:fb773f73a4be
397 { 397 {
398 int nr; 398 int nr;
399 char_u *str; 399 char_u *str;
400 dictitem_T *di; 400 dictitem_T *di;
401 401
402 if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0) 402 if ((nr = dict_get_number_def(d, (char_u *)"minwidth", -1)) >= 0)
403 wp->w_minwidth = nr; 403 wp->w_minwidth = nr;
404 if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0) 404 if ((nr = dict_get_number_def(d, (char_u *)"minheight", -1)) >= 0)
405 wp->w_minheight = nr; 405 wp->w_minheight = nr;
406 if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0) 406 if ((nr = dict_get_number_def(d, (char_u *)"maxwidth", -1)) >= 0)
407 wp->w_maxwidth = nr; 407 wp->w_maxwidth = nr;
408 if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) 408 if ((nr = dict_get_number_def(d, (char_u *)"maxheight", -1)) >= 0)
409 wp->w_maxheight = nr; 409 wp->w_maxheight = nr;
410 410
411 nr = popup_options_one(d, (char_u *)"line"); 411 nr = popup_options_one(d, (char_u *)"line");
412 if (nr != MAXCOL) 412 if (nr != MAXCOL)
413 wp->w_wantline = nr; 413 wp->w_wantline = nr;
607 607
608 // TODO: flip 608 // TODO: flip
609 609
610 di = dict_find(dict, (char_u *)"firstline", -1); 610 di = dict_find(dict, (char_u *)"firstline", -1);
611 if (di != NULL) 611 if (di != NULL)
612 {
612 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); 613 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline");
613 if (wp->w_firstline < 0) 614 if (wp->w_firstline < 0)
614 wp->w_firstline = 0; 615 wp->w_firstline = -1;
616 }
615 617
616 di = dict_find(dict, (char_u *)"scrollbar", -1); 618 di = dict_find(dict, (char_u *)"scrollbar", -1);
617 if (di != NULL) 619 if (di != NULL)
618 wp->w_want_scrollbar = dict_get_number(dict, (char_u *)"scrollbar"); 620 wp->w_want_scrollbar = dict_get_number(dict, (char_u *)"scrollbar");
619 621
1144 allow_adjust_left = FALSE; 1146 allow_adjust_left = FALSE;
1145 maxwidth = wp->w_maxwidth; 1147 maxwidth = wp->w_maxwidth;
1146 } 1148 }
1147 1149
1148 // start at the desired first line 1150 // start at the desired first line
1149 if (wp->w_firstline != 0) 1151 if (wp->w_firstline > 0)
1150 wp->w_topline = wp->w_firstline; 1152 wp->w_topline = wp->w_firstline;
1151 if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) 1153 if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
1152 wp->w_topline = wp->w_buffer->b_ml.ml_line_count; 1154 wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
1153 1155
1154 // Compute width based on longest text line and the 'wrap' option. 1156 // Compute width based on longest text line and the 'wrap' option.
1155 // Use a minimum width of one, so that something shows when there is no 1157 // Use a minimum width of one, so that something shows when there is no
1156 // text. 1158 // text.
1159 // When "firstline" is -1 then start with the last buffer line and go
1160 // backwards.
1157 // TODO: more accurate wrapping 1161 // TODO: more accurate wrapping
1158 wp->w_width = 1; 1162 wp->w_width = 1;
1159 for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) 1163 if (wp->w_firstline < 0)
1164 lnum = wp->w_buffer->b_ml.ml_line_count;
1165 else
1166 lnum = wp->w_topline;
1167 while (lnum >= 1 && lnum <= wp->w_buffer->b_ml.ml_line_count)
1160 { 1168 {
1161 int len; 1169 int len;
1162 int w_width = wp->w_width; 1170 int w_width = wp->w_width;
1163 1171
1164 // Count Tabs for what they are worth and compute the length based on 1172 // Count Tabs for what they are worth and compute the length based on
1204 if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth) 1212 if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth)
1205 wp->w_width = wp->w_maxwidth; 1213 wp->w_width = wp->w_maxwidth;
1206 } 1214 }
1207 // do not use the width of lines we're not going to show 1215 // do not use the width of lines we're not going to show
1208 if (wp->w_maxheight > 0 1216 if (wp->w_maxheight > 0
1209 && lnum - wp->w_topline + 1 + wrapped > wp->w_maxheight) 1217 && (wp->w_firstline >= 0
1218 ? lnum - wp->w_topline
1219 : wp->w_buffer->b_ml.ml_line_count - lnum)
1220 + 1 + wrapped > wp->w_maxheight)
1210 break; 1221 break;
1211 } 1222
1223 if (wp->w_firstline < 0)
1224 --lnum;
1225 else
1226 ++lnum;
1227 }
1228
1229 if (wp->w_firstline < 0)
1230 wp->w_topline = lnum > 0 ? lnum + 1 : lnum;
1212 1231
1213 wp->w_has_scrollbar = wp->w_want_scrollbar 1232 wp->w_has_scrollbar = wp->w_want_scrollbar
1214 && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); 1233 && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count);
1215 if (wp->w_has_scrollbar) 1234 if (wp->w_has_scrollbar)
1216 { 1235 {