Mercurial > vim
comparison src/popupmnu.c @ 10326:7d10572eaba4 v8.0.0058
commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Nov 4 20:08:52 2016 +0100
patch 8.0.0058
Problem: Positioning of the popup menu is not good.
Solution: Position it better. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 04 Nov 2016 20:15:04 +0100 |
parents | 210af8588e8a |
children | 4d98f501d1c5 |
comparison
equal
deleted
inserted
replaced
10325:a1545399059e | 10326:7d10572eaba4 |
---|---|
52 int def_width; | 52 int def_width; |
53 int max_width; | 53 int max_width; |
54 int kind_width; | 54 int kind_width; |
55 int extra_width; | 55 int extra_width; |
56 int i; | 56 int i; |
57 int top_clear; | |
58 int row; | 57 int row; |
59 int context_lines; | 58 int context_lines; |
60 int col; | 59 int col; |
61 int above_row = cmdline_row; | 60 int above_row; |
61 int below_row; | |
62 int redo_count = 0; | 62 int redo_count = 0; |
63 win_T *pvwin; | |
63 | 64 |
64 redo: | 65 redo: |
65 def_width = PUM_DEF_WIDTH; | 66 def_width = PUM_DEF_WIDTH; |
66 max_width = 0; | 67 max_width = 0; |
67 kind_width = 0; | 68 kind_width = 0; |
68 extra_width = 0; | 69 extra_width = 0; |
70 above_row = 0; | |
71 below_row = cmdline_row; | |
69 | 72 |
70 /* Pretend the pum is already there to avoid that must_redraw is set when | 73 /* Pretend the pum is already there to avoid that must_redraw is set when |
71 * 'cuc' is on. */ | 74 * 'cuc' is on. */ |
72 pum_array = (pumitem_T *)1; | 75 pum_array = (pumitem_T *)1; |
73 validate_cursor_col(); | 76 validate_cursor_col(); |
74 pum_array = NULL; | 77 pum_array = NULL; |
75 | 78 |
76 row = curwin->w_wrow + W_WINROW(curwin); | 79 row = curwin->w_wrow + W_WINROW(curwin); |
77 | 80 |
78 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | 81 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
79 if (firstwin->w_p_pvw) | 82 FOR_ALL_WINDOWS(pvwin) |
80 top_clear = firstwin->w_height; | 83 if (pvwin->w_p_pvw) |
81 else | 84 break; |
82 #endif | 85 if (pvwin != NULL) |
83 top_clear = 0; | 86 { |
84 | 87 if (W_WINROW(pvwin) < W_WINROW(curwin)) |
85 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | 88 above_row = W_WINROW(pvwin) + pvwin->w_height; |
86 /* When the preview window is at the bottom stop just above it. Also | 89 else if (W_WINROW(pvwin) > W_WINROW(curwin) + curwin->w_height) |
87 * avoid drawing over the status line so that it's clear there is a window | 90 below_row = W_WINROW(pvwin); |
88 * boundary. */ | 91 } |
89 if (lastwin->w_p_pvw) | |
90 above_row -= lastwin->w_height + lastwin->w_status_height + 1; | |
91 #endif | 92 #endif |
92 | 93 |
93 /* | 94 /* |
94 * Figure out the size and position of the pum. | 95 * Figure out the size and position of the pum. |
95 */ | 96 */ |
100 if (p_ph > 0 && pum_height > p_ph) | 101 if (p_ph > 0 && pum_height > p_ph) |
101 pum_height = p_ph; | 102 pum_height = p_ph; |
102 | 103 |
103 /* Put the pum below "row" if possible. If there are few lines decide on | 104 /* Put the pum below "row" if possible. If there are few lines decide on |
104 * where there is more room. */ | 105 * where there is more room. */ |
105 if (row + 2 >= above_row - pum_height | 106 if (row - above_row >= below_row - row) |
106 && row > (above_row - top_clear) / 2) | |
107 { | 107 { |
108 /* pum above "row" */ | 108 /* pum above "row" */ |
109 | 109 |
110 /* Leave two lines of context if possible */ | 110 /* Leave two lines of context if possible */ |
111 if (curwin->w_wrow - curwin->w_cline_row >= 2) | 111 if (curwin->w_wrow - curwin->w_cline_row >= 2) |
139 else | 139 else |
140 context_lines = curwin->w_cline_row | 140 context_lines = curwin->w_cline_row |
141 + curwin->w_cline_height - curwin->w_wrow; | 141 + curwin->w_cline_height - curwin->w_wrow; |
142 | 142 |
143 pum_row = row + context_lines; | 143 pum_row = row + context_lines; |
144 if (size > above_row - pum_row) | 144 if (size > below_row - pum_row) |
145 pum_height = above_row - pum_row; | 145 pum_height = below_row - pum_row; |
146 else | 146 else |
147 pum_height = size; | 147 pum_height = size; |
148 if (p_ph > 0 && pum_height > p_ph) | 148 if (p_ph > 0 && pum_height > p_ph) |
149 pum_height = p_ph; | 149 pum_height = p_ph; |
150 } | 150 } |
152 /* don't display when we only have room for one line */ | 152 /* don't display when we only have room for one line */ |
153 if (pum_height < 1 || (pum_height == 1 && size > 1)) | 153 if (pum_height < 1 || (pum_height == 1 && size > 1)) |
154 return; | 154 return; |
155 | 155 |
156 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | 156 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
157 /* If there is a preview window at the top avoid drawing over it. */ | 157 /* If there is a preview window at the above avoid drawing over it. */ |
158 if (firstwin->w_p_pvw | 158 if (pvwin != NULL && pum_row < above_row && pum_height > above_row) |
159 && pum_row < firstwin->w_height | 159 { |
160 && pum_height > firstwin->w_height + 4) | 160 pum_row += above_row; |
161 { | 161 pum_height -= above_row; |
162 pum_row += firstwin->w_height; | |
163 pum_height -= firstwin->w_height; | |
164 } | 162 } |
165 #endif | 163 #endif |
166 | 164 |
167 /* Compute the width of the widest match and the widest extra. */ | 165 /* Compute the width of the widest match and the widest extra. */ |
168 for (i = 0; i < size; ++i) | 166 for (i = 0; i < size; ++i) |