comparison src/popupmnu.c @ 13331:1ba4f926247c v8.0.1540

patch 8.0.1540: popup menu positioning fails with longer string commit https://github.com/vim/vim/commit/2b10bcbfc1c025bf7e6358326ee70105e7d30e96 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 24 21:25:44 2018 +0100 patch 8.0.1540: popup menu positioning fails with longer string Problem: Popup menu positioning fails with longer string. Solution: Only align with right side of window when width is less than 'pumwidth' (closes #2661)
author Christian Brabandt <cb@256bit.org>
date Sat, 24 Feb 2018 21:30:05 +0100
parents 2c639a9a4def
children 244ff1b6d2ad
comparison
equal deleted inserted replaced
13330:6f51f5408677 13331:1ba4f926247c
67 } 67 }
68 68
69 /* 69 /*
70 * Show the popup menu with items "array[size]". 70 * Show the popup menu with items "array[size]".
71 * "array" must remain valid until pum_undisplay() is called! 71 * "array" must remain valid until pum_undisplay() is called!
72 * When possible the leftmost character is aligned with screen column "col". 72 * When possible the leftmost character is aligned with cursor column.
73 * The menu appears above the screen line "row" or at "row" + "height" - 1. 73 * The menu appears above the screen line "row" or at "row" + "height" - 1.
74 */ 74 */
75 void 75 void
76 pum_display( 76 pum_display(
77 pumitem_T *array, 77 pumitem_T *array,
81 { 81 {
82 int def_width; 82 int def_width;
83 int max_width; 83 int max_width;
84 int row; 84 int row;
85 int context_lines; 85 int context_lines;
86 int col; 86 int cursor_col;
87 int above_row; 87 int above_row;
88 int below_row; 88 int below_row;
89 int redo_count = 0; 89 int redo_count = 0;
90 #if defined(FEAT_QUICKFIX) 90 #if defined(FEAT_QUICKFIX)
91 win_T *pvwin; 91 win_T *pvwin;
197 max_width = pum_base_width; 197 max_width = pum_base_width;
198 198
199 /* Calculate column */ 199 /* Calculate column */
200 #ifdef FEAT_RIGHTLEFT 200 #ifdef FEAT_RIGHTLEFT
201 if (curwin->w_p_rl) 201 if (curwin->w_p_rl)
202 col = curwin->w_wincol + curwin->w_width - curwin->w_wcol - 1; 202 cursor_col = curwin->w_wincol + curwin->w_width
203 - curwin->w_wcol - 1;
203 else 204 else
204 #endif 205 #endif
205 col = curwin->w_wincol + curwin->w_wcol; 206 cursor_col = curwin->w_wincol + curwin->w_wcol;
206 207
207 /* if there are more items than room we need a scrollbar */ 208 /* if there are more items than room we need a scrollbar */
208 if (pum_height < size) 209 if (pum_height < size)
209 { 210 {
210 pum_scrollbar = 1; 211 pum_scrollbar = 1;
214 pum_scrollbar = 0; 215 pum_scrollbar = 0;
215 216
216 if (def_width < max_width) 217 if (def_width < max_width)
217 def_width = max_width; 218 def_width = max_width;
218 219
219 if (((col < Columns - p_pw || col < Columns - max_width) 220 if (((cursor_col < Columns - p_pw
221 || cursor_col < Columns - max_width)
220 #ifdef FEAT_RIGHTLEFT 222 #ifdef FEAT_RIGHTLEFT
221 && !curwin->w_p_rl) 223 && !curwin->w_p_rl)
222 || (curwin->w_p_rl && (col > p_pw || col > max_width) 224 || (curwin->w_p_rl
225 && (cursor_col > p_pw || cursor_col > max_width)
223 #endif 226 #endif
224 )) 227 ))
225 { 228 {
226 /* align pum column with "col" */ 229 /* align pum with "cursor_col" */
227 pum_col = col; 230 pum_col = cursor_col;
228 231
229 /* start with the maximum space available */ 232 /* start with the maximum space available */
230 #ifdef FEAT_RIGHTLEFT 233 #ifdef FEAT_RIGHTLEFT
231 if (curwin->w_p_rl) 234 if (curwin->w_p_rl)
232 pum_width = pum_col - pum_scrollbar + 1; 235 pum_width = pum_col - pum_scrollbar + 1;
235 pum_width = Columns - pum_col - pum_scrollbar; 238 pum_width = Columns - pum_col - pum_scrollbar;
236 239
237 if (pum_width > max_width + pum_kind_width + pum_extra_width + 1 240 if (pum_width > max_width + pum_kind_width + pum_extra_width + 1
238 && pum_width > p_pw) 241 && pum_width > p_pw)
239 { 242 {
240 /* the width is too much, make it narrower */ 243 /* the width is more than needed for the items, make it
244 * narrower */
241 pum_width = max_width + pum_kind_width + pum_extra_width + 1; 245 pum_width = max_width + pum_kind_width + pum_extra_width + 1;
242 if (pum_width < p_pw) 246 if (pum_width < p_pw)
243 pum_width = p_pw; 247 pum_width = p_pw;
244 } 248 }
245 else if (((col > p_pw || col > max_width) 249 else if (((cursor_col > p_pw || cursor_col > max_width)
246 #ifdef FEAT_RIGHTLEFT 250 #ifdef FEAT_RIGHTLEFT
247 && !curwin->w_p_rl) 251 && !curwin->w_p_rl)
248 || (curwin->w_p_rl && (col < Columns - p_pw 252 || (curwin->w_p_rl && (cursor_col < Columns - p_pw
249 || col < Columns - max_width) 253 || cursor_col < Columns - max_width)
250 #endif 254 #endif
251 )) 255 ))
252 { 256 {
253 /* align right pum edge with "col" */ 257 /* align pum edge with "cursor_col" */
254 #ifdef FEAT_RIGHTLEFT 258 #ifdef FEAT_RIGHTLEFT
255 if (curwin->w_p_rl 259 if (curwin->w_p_rl
256 && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1) 260 && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1)
257 { 261 {
258 pum_col = col + max_width + pum_scrollbar + 1; 262 pum_col = cursor_col + max_width + pum_scrollbar + 1;
259 if (pum_col >= Columns) 263 if (pum_col >= Columns)
260 pum_col = Columns - 1; 264 pum_col = Columns - 1;
261 } 265 }
262 else if (!curwin->w_p_rl) 266 else if (!curwin->w_p_rl)
263 #endif 267 #endif
264 { 268 {
265 if (curwin->w_wincol > Columns - max_width - pum_scrollbar) 269 if (curwin->w_wincol > Columns - max_width - pum_scrollbar
270 && max_width <= p_pw)
266 { 271 {
272 /* use full width to end of the screen */
267 pum_col = Columns - max_width - pum_scrollbar; 273 pum_col = Columns - max_width - pum_scrollbar;
268 if (pum_col < 0) 274 if (pum_col < 0)
269 pum_col = 0; 275 pum_col = 0;
270 } 276 }
271 } 277 }