comparison src/popupwin.c @ 17047:6400d1ad5e4b v8.1.1523

patch 8.1.1523: cannot show range of buffer lines in popup window commit https://github.com/vim/vim/commit/8d241040310a6a27c28d62fa04558f2bfaa5ebde Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 12 23:40:01 2019 +0200 patch 8.1.1523: cannot show range of buffer lines in popup window Problem: Cannot show range of buffer lines in popup window. Solution: Add the "firstline" property. (closes https://github.com/vim/vim/issues/4523)
author Bram Moolenaar <Bram@vim.org>
date Wed, 12 Jun 2019 23:45:04 +0200
parents 7fe328ad5573
children 221d4b82bc0b
comparison
equal deleted inserted replaced
17046:b1b684caeb40 17047:6400d1ad5e4b
223 // Option values resulting in setting an option. 223 // Option values resulting in setting an option.
224 str = dict_get_string(dict, (char_u *)"highlight", FALSE); 224 str = dict_get_string(dict, (char_u *)"highlight", FALSE);
225 if (str != NULL) 225 if (str != NULL)
226 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, 226 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
227 str, OPT_FREE|OPT_LOCAL, 0); 227 str, OPT_FREE|OPT_LOCAL, 0);
228
229 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline");
230 if (wp->w_firstline < 1)
231 wp->w_firstline = 1;
228 232
229 di = dict_find(dict, (char_u *)"wrap", -1); 233 di = dict_find(dict, (char_u *)"wrap", -1);
230 if (di != NULL) 234 if (di != NULL)
231 { 235 {
232 nr = dict_get_number(dict, (char_u *)"wrap"); 236 nr = dict_get_number(dict, (char_u *)"wrap");
517 { 521 {
518 allow_adjust_left = FALSE; 522 allow_adjust_left = FALSE;
519 maxwidth = wp->w_maxwidth; 523 maxwidth = wp->w_maxwidth;
520 } 524 }
521 525
526 // start at the desired first line
527 wp->w_topline = wp->w_firstline;
528 if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
529 wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
530
522 // Compute width based on longest text line and the 'wrap' option. 531 // Compute width based on longest text line and the 'wrap' option.
523 // TODO: more accurate wrapping 532 // TODO: more accurate wrapping
524 wp->w_width = 0; 533 wp->w_width = 0;
525 for (lnum = 1; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) 534 for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum)
526 { 535 {
527 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); 536 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE));
528 537
529 if (wp->w_p_wrap) 538 if (wp->w_p_wrap)
530 { 539 {
554 maxwidth += shift_by; 563 maxwidth += shift_by;
555 wp->w_width = maxwidth; 564 wp->w_width = maxwidth;
556 } 565 }
557 if (wp->w_width < len) 566 if (wp->w_width < len)
558 wp->w_width = len; 567 wp->w_width = len;
568 // do not use the width of lines we're not going to show
569 if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count
570 - wp->w_topline + 1 + wrapped > wp->w_maxheight)
571 break;
559 } 572 }
560 573
561 if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth) 574 if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth)
562 wp->w_width = wp->w_minwidth; 575 wp->w_width = wp->w_minwidth;
563 if (wp->w_width > maxwidth) 576 if (wp->w_width > maxwidth)
571 // No truncation, because that would change the height. 584 // No truncation, because that would change the height.
572 if (wp->w_width + extra_width < wp->w_wantcol) 585 if (wp->w_width + extra_width < wp->w_wantcol)
573 wp->w_wincol = wp->w_wantcol - (wp->w_width + extra_width); 586 wp->w_wincol = wp->w_wantcol - (wp->w_width + extra_width);
574 } 587 }
575 588
576 wp->w_height = wp->w_buffer->b_ml.ml_line_count + wrapped; 589 wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline
590 + 1 + wrapped;
577 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) 591 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight)
578 wp->w_height = wp->w_minheight; 592 wp->w_height = wp->w_minheight;
579 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) 593 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
580 wp->w_height = wp->w_maxheight; 594 wp->w_height = wp->w_maxheight;
581 if (wp->w_height > Rows - wp->w_winrow) 595 if (wp->w_height > Rows - wp->w_winrow)
1131 dict_add_number(dict, "col", wp->w_wantcol); 1145 dict_add_number(dict, "col", wp->w_wantcol);
1132 dict_add_number(dict, "minwidth", wp->w_minwidth); 1146 dict_add_number(dict, "minwidth", wp->w_minwidth);
1133 dict_add_number(dict, "minheight", wp->w_minheight); 1147 dict_add_number(dict, "minheight", wp->w_minheight);
1134 dict_add_number(dict, "maxheight", wp->w_maxheight); 1148 dict_add_number(dict, "maxheight", wp->w_maxheight);
1135 dict_add_number(dict, "maxwidth", wp->w_maxwidth); 1149 dict_add_number(dict, "maxwidth", wp->w_maxwidth);
1150 dict_add_number(dict, "firstline", wp->w_firstline);
1136 dict_add_number(dict, "zindex", wp->w_zindex); 1151 dict_add_number(dict, "zindex", wp->w_zindex);
1137 dict_add_number(dict, "fixed", wp->w_popup_fixed); 1152 dict_add_number(dict, "fixed", wp->w_popup_fixed);
1138 1153
1139 for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); 1154 for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
1140 ++i) 1155 ++i)