comparison src/popupwin.c @ 16896:52fc577a087d v8.1.1449

patch 8.1.1449: popup text truncated at end of screen commit https://github.com/vim/vim/commit/042fb4b449bb5d8494698803e766dfd288b458cf Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 2 14:49:56 2019 +0200 patch 8.1.1449: popup text truncated at end of screen Problem: Popup text truncated at end of screen. Solution: Move popup left if needed. Add the "fixed" property to disable that. (Ben Jackson , closes #4466)
author Bram Moolenaar <Bram@vim.org>
date Sun, 02 Jun 2019 15:00:06 +0200
parents 60c9ac14a2ec
children 16fd1bb2e675
comparison
equal deleted inserted replaced
16895:44f703825130 16896:52fc577a087d
81 if (nr > 0) 81 if (nr > 0)
82 wp->w_wantline = nr; 82 wp->w_wantline = nr;
83 nr = popup_options_one(dict, (char_u *)"col"); 83 nr = popup_options_one(dict, (char_u *)"col");
84 if (nr > 0) 84 if (nr > 0)
85 wp->w_wantcol = nr; 85 wp->w_wantcol = nr;
86
87 wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0;
86 88
87 str = dict_get_string(dict, (char_u *)"pos", FALSE); 89 str = dict_get_string(dict, (char_u *)"pos", FALSE);
88 if (str != NULL) 90 if (str != NULL)
89 { 91 {
90 for (nr = 0; 92 for (nr = 0;
377 linenr_T lnum; 379 linenr_T lnum;
378 int wrapped = 0; 380 int wrapped = 0;
379 int maxwidth; 381 int maxwidth;
380 int center_vert = FALSE; 382 int center_vert = FALSE;
381 int center_hor = FALSE; 383 int center_hor = FALSE;
384 int allow_adjust_left = !wp->w_popup_fixed;
382 385
383 wp->w_winrow = 0; 386 wp->w_winrow = 0;
384 wp->w_wincol = 0; 387 wp->w_wincol = 0;
385 if (wp->w_popup_pos == POPPOS_CENTER) 388 if (wp->w_popup_pos == POPPOS_CENTER)
386 { 389 {
410 wp->w_wincol = Columns - 3; 413 wp->w_wincol = Columns - 3;
411 } 414 }
412 } 415 }
413 416
414 // When centering or right aligned, use maximum width. 417 // When centering or right aligned, use maximum width.
415 // When left aligned use the space available. 418 // When left aligned use the space available, but shift to the left when we
419 // hit the right of the screen.
416 maxwidth = Columns - wp->w_wincol; 420 maxwidth = Columns - wp->w_wincol;
417 if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth) 421 if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth)
422 {
423 allow_adjust_left = FALSE;
418 maxwidth = wp->w_maxwidth; 424 maxwidth = wp->w_maxwidth;
425 }
419 426
420 // Compute width based on longest text line and the 'wrap' option. 427 // Compute width based on longest text line and the 'wrap' option.
421 // TODO: more accurate wrapping 428 // TODO: more accurate wrapping
422 wp->w_width = 0; 429 wp->w_width = 0;
423 for (lnum = 1; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) 430 for (lnum = 1; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum)
424 { 431 {
425 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); 432 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE));
426 433
427 while (wp->w_p_wrap && len > maxwidth) 434 if (wp->w_p_wrap)
428 { 435 {
429 ++wrapped; 436 while (len > maxwidth)
430 len -= maxwidth; 437 {
438 ++wrapped;
439 len -= maxwidth;
440 wp->w_width = maxwidth;
441 }
442 }
443 else if (len > maxwidth
444 && allow_adjust_left
445 && (wp->w_popup_pos == POPPOS_TOPLEFT
446 || wp->w_popup_pos == POPPOS_BOTLEFT))
447 {
448 // adjust leftwise to fit text on screen
449 int shift_by = ( len - maxwidth );
450
451 if ( shift_by > wp->w_wincol )
452 {
453 int truncate_shift = shift_by - wp->w_wincol;
454 len -= truncate_shift;
455 shift_by -= truncate_shift;
456 }
457
458 wp->w_wincol -= shift_by;
459 maxwidth += shift_by;
431 wp->w_width = maxwidth; 460 wp->w_width = maxwidth;
432 } 461 }
433 if (wp->w_width < len) 462 if (wp->w_width < len)
434 wp->w_width = len; 463 wp->w_width = len;
435 } 464 }
893 dict_add_number(dict, "minwidth", wp->w_minwidth); 922 dict_add_number(dict, "minwidth", wp->w_minwidth);
894 dict_add_number(dict, "minheight", wp->w_minheight); 923 dict_add_number(dict, "minheight", wp->w_minheight);
895 dict_add_number(dict, "maxheight", wp->w_maxheight); 924 dict_add_number(dict, "maxheight", wp->w_maxheight);
896 dict_add_number(dict, "maxwidth", wp->w_maxwidth); 925 dict_add_number(dict, "maxwidth", wp->w_maxwidth);
897 dict_add_number(dict, "zindex", wp->w_zindex); 926 dict_add_number(dict, "zindex", wp->w_zindex);
927 dict_add_number(dict, "fixed", wp->w_popup_fixed);
898 928
899 for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); 929 for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
900 ++i) 930 ++i)
901 if (wp->w_popup_pos == poppos_entries[i].pp_val) 931 if (wp->w_popup_pos == poppos_entries[i].pp_val)
902 { 932 {