Mercurial > vim
comparison src/popupwin.c @ 22403:3351d2cd3f1f v8.2.1750
patch 8.2.1750: popup_setoptions() setting firstline fails if cursorline set
Commit: https://github.com/vim/vim/commit/3697c9bbae755831d3cf2f11179aaff29e343f51
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 26 22:03:00 2020 +0200
patch 8.2.1750: popup_setoptions() setting firstline fails if cursorline set
Problem: Setting firstline with popup_setoptions() fails if cursorline is
set.
Solution: Use apply_options(). Update the popup before applying "zz".
(closes #7010)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 26 Sep 2020 22:15:04 +0200 |
parents | b2cb2a321af9 |
children | 909ce065e99a |
comparison
equal
deleted
inserted
replaced
22402:337df0dbfe0a | 22403:3351d2cd3f1f |
---|---|
577 popup_show_curline(win_T *wp) | 577 popup_show_curline(win_T *wp) |
578 { | 578 { |
579 if (wp->w_cursor.lnum < wp->w_topline) | 579 if (wp->w_cursor.lnum < wp->w_topline) |
580 wp->w_topline = wp->w_cursor.lnum; | 580 wp->w_topline = wp->w_cursor.lnum; |
581 else if (wp->w_cursor.lnum >= wp->w_botline | 581 else if (wp->w_cursor.lnum >= wp->w_botline |
582 && (curwin->w_valid & VALID_BOTLINE)) | 582 && (wp->w_valid & VALID_BOTLINE)) |
583 { | 583 { |
584 wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1; | 584 wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1; |
585 if (wp->w_topline < 1) | 585 if (wp->w_topline < 1) |
586 wp->w_topline = 1; | 586 wp->w_topline = 1; |
587 else if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) | 587 else if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) |
929 } | 929 } |
930 } | 930 } |
931 | 931 |
932 /* | 932 /* |
933 * Go through the options in "dict" and apply them to popup window "wp". | 933 * Go through the options in "dict" and apply them to popup window "wp". |
934 * Only used when creating a new popup window. | 934 * "create" is TRUE when creating a new popup window. |
935 */ | 935 */ |
936 static void | 936 static void |
937 apply_options(win_T *wp, dict_T *dict) | 937 apply_options(win_T *wp, dict_T *dict, int create) |
938 { | 938 { |
939 int nr; | 939 int nr; |
940 | 940 |
941 apply_move_options(wp, dict); | 941 apply_move_options(wp, dict); |
942 | 942 |
943 set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1, | 943 if (create) |
944 set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1, | |
944 (char_u *)"no", OPT_FREE|OPT_LOCAL, 0); | 945 (char_u *)"no", OPT_FREE|OPT_LOCAL, 0); |
945 | 946 |
946 apply_general_options(wp, dict); | 947 apply_general_options(wp, dict); |
947 | 948 |
948 nr = dict_get_bool(dict, (char_u *)"hidden", FALSE); | 949 nr = dict_get_bool(dict, (char_u *)"hidden", FALSE); |
949 if (nr > 0) | 950 if (nr > 0) |
950 wp->w_popup_flags |= POPF_HIDDEN; | 951 wp->w_popup_flags |= POPF_HIDDEN; |
951 | 952 |
952 // when "firstline" and "cursorline" are both set move the cursor to the | 953 // when "firstline" and "cursorline" are both set and the cursor would be |
953 // "firstline". | 954 // above or below the displayed lines, move the cursor to "firstline". |
954 if (wp->w_firstline > 0 && (wp->w_popup_flags & POPF_CURSORLINE)) | 955 if (wp->w_firstline > 0 && (wp->w_popup_flags & POPF_CURSORLINE)) |
955 { | 956 { |
956 if (wp->w_firstline > wp->w_buffer->b_ml.ml_line_count) | 957 if (wp->w_firstline > wp->w_buffer->b_ml.ml_line_count) |
957 wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; | 958 wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; |
958 else | 959 else if (wp->w_cursor.lnum < wp->w_firstline |
960 || wp->w_cursor.lnum >= wp->w_firstline + wp->w_height) | |
959 wp->w_cursor.lnum = wp->w_firstline; | 961 wp->w_cursor.lnum = wp->w_firstline; |
960 wp->w_topline = wp->w_cursor.lnum; | 962 wp->w_topline = wp->w_firstline; |
961 curwin->w_valid &= ~VALID_BOTLINE; | 963 wp->w_valid &= ~VALID_BOTLINE; |
962 } | 964 } |
963 | 965 |
964 popup_mask_refresh = TRUE; | 966 popup_mask_refresh = TRUE; |
965 popup_highlight_curline(wp); | 967 popup_highlight_curline(wp); |
966 } | 968 } |
2104 wp->w_popup_fixed = 0; | 2106 wp->w_popup_fixed = 0; |
2105 wp->w_filter_mode = MODE_ALL; | 2107 wp->w_filter_mode = MODE_ALL; |
2106 | 2108 |
2107 if (d != NULL) | 2109 if (d != NULL) |
2108 // Deal with options. | 2110 // Deal with options. |
2109 apply_options(wp, d); | 2111 apply_options(wp, d, TRUE); |
2110 | 2112 |
2111 #ifdef FEAT_TIMERS | 2113 #ifdef FEAT_TIMERS |
2112 if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) | 2114 if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) |
2113 popup_add_timeout(wp, 3000); | 2115 popup_add_timeout(wp, 3000); |
2114 #endif | 2116 #endif |
2760 return; | 2762 return; |
2761 } | 2763 } |
2762 dict = argvars[1].vval.v_dict; | 2764 dict = argvars[1].vval.v_dict; |
2763 old_firstline = wp->w_firstline; | 2765 old_firstline = wp->w_firstline; |
2764 | 2766 |
2765 apply_move_options(wp, dict); | 2767 apply_options(wp, dict, FALSE); |
2766 apply_general_options(wp, dict); | |
2767 | 2768 |
2768 if (old_firstline != wp->w_firstline) | 2769 if (old_firstline != wp->w_firstline) |
2769 redraw_win_later(wp, NOT_VALID); | 2770 redraw_win_later(wp, NOT_VALID); |
2770 popup_mask_refresh = TRUE; | |
2771 popup_highlight_curline(wp); | |
2772 popup_adjust_position(wp); | 2771 popup_adjust_position(wp); |
2773 } | 2772 } |
2774 | 2773 |
2775 /* | 2774 /* |
2776 * popup_getpos({id}) | 2775 * popup_getpos({id}) |
3465 static int | 3464 static int |
3466 popup_need_position_adjust(win_T *wp) | 3465 popup_need_position_adjust(win_T *wp) |
3467 { | 3466 { |
3468 if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) | 3467 if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
3469 return TRUE; | 3468 return TRUE; |
3470 if (win_valid(wp->w_popup_prop_win)) | 3469 if (win_valid(wp->w_popup_prop_win) |
3471 return wp->w_popup_prop_changedtick | 3470 && (wp->w_popup_prop_changedtick |
3472 != CHANGEDTICK(wp->w_popup_prop_win->w_buffer) | 3471 != CHANGEDTICK(wp->w_popup_prop_win->w_buffer) |
3473 || wp->w_popup_prop_topline != wp->w_popup_prop_win->w_topline | 3472 || wp->w_popup_prop_topline != wp->w_popup_prop_win->w_topline)) |
3474 || ((wp->w_popup_flags & POPF_CURSORLINE) | 3473 return TRUE; |
3475 && wp->w_cursor.lnum != wp->w_popup_last_curline); | 3474 |
3476 return FALSE; | 3475 // May need to adjust the width if the cursor moved. |
3476 return wp->w_cursor.lnum != wp->w_popup_last_curline; | |
3477 } | 3477 } |
3478 | 3478 |
3479 /* | 3479 /* |
3480 * Update "popup_mask" if needed. | 3480 * Update "popup_mask" if needed. |
3481 * Also recomputes the popup size and positions. | 3481 * Also recomputes the popup size and positions. |
3645 vim_free(plines_cache); | 3645 vim_free(plines_cache); |
3646 } | 3646 } |
3647 } | 3647 } |
3648 | 3648 |
3649 /* | 3649 /* |
3650 * If the current window is a popup and something relevant changed, recompute | |
3651 * the position and size. | |
3652 */ | |
3653 void | |
3654 may_update_popup_position(void) | |
3655 { | |
3656 if (popup_is_popup(curwin) && popup_need_position_adjust(curwin)) | |
3657 popup_adjust_position(curwin); | |
3658 } | |
3659 | |
3660 /* | |
3650 * Return a string of "len" spaces in IObuff. | 3661 * Return a string of "len" spaces in IObuff. |
3651 */ | 3662 */ |
3652 static char_u * | 3663 static char_u * |
3653 get_spaces(int len) | 3664 get_spaces(int len) |
3654 { | 3665 { |