Mercurial > vim
comparison src/popupwin.c @ 16837:18593056d8f1 v8.1.1420
patch 8.1.1420: popup window size only uses first line length
commit https://github.com/vim/vim/commit/88c4e1f06905983870175a473683e81312d14c64
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed May 29 23:14:28 2019 +0200
patch 8.1.1420: popup window size only uses first line length
Problem: Popup window size only uses first line length.
Solution: Use the longest line. (Ben Jackson, closes https://github.com/vim/vim/issues/4451) Also deal with
wrapping lines.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 29 May 2019 23:15:05 +0200 |
parents | 6699c03347d2 |
children | 032d5335987e |
comparison
equal
deleted
inserted
replaced
16836:237a080e55a3 | 16837:18593056d8f1 |
---|---|
152 * Adjust the position and size of the popup to fit on the screen. | 152 * Adjust the position and size of the popup to fit on the screen. |
153 */ | 153 */ |
154 static void | 154 static void |
155 popup_adjust_position(win_T *wp) | 155 popup_adjust_position(win_T *wp) |
156 { | 156 { |
157 linenr_T lnum; | |
158 int wrapped = 0; | |
159 int maxwidth; | |
160 | |
157 // TODO: Compute the size and position properly. | 161 // TODO: Compute the size and position properly. |
158 if (wp->w_wantline > 0) | 162 if (wp->w_wantline > 0) |
159 wp->w_winrow = wp->w_wantline - 1; | 163 wp->w_winrow = wp->w_wantline - 1; |
160 else | 164 else |
161 // TODO: better default | 165 // TODO: better default |
169 // TODO: better default | 173 // TODO: better default |
170 wp->w_wincol = Columns > 20 ? Columns / 2 - 10 : 0; | 174 wp->w_wincol = Columns > 20 ? Columns / 2 - 10 : 0; |
171 if (wp->w_wincol >= Columns - 3) | 175 if (wp->w_wincol >= Columns - 3) |
172 wp->w_wincol = Columns - 3; | 176 wp->w_wincol = Columns - 3; |
173 | 177 |
174 // TODO: set width based on longest text line and the 'wrap' option | 178 maxwidth = Columns - wp->w_wincol; |
175 wp->w_width = vim_strsize(ml_get_buf(wp->w_buffer, 1, FALSE)); | 179 if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth) |
180 maxwidth = wp->w_maxwidth; | |
181 | |
182 // Compute width based on longest text line and the 'wrap' option. | |
183 // TODO: more accurate wrapping | |
184 wp->w_width = 0; | |
185 for (lnum = 1; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) | |
186 { | |
187 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); | |
188 | |
189 while (wp->w_p_wrap && len > maxwidth) | |
190 { | |
191 ++wrapped; | |
192 len -= maxwidth; | |
193 wp->w_width = maxwidth; | |
194 } | |
195 if (wp->w_width < len) | |
196 wp->w_width = len; | |
197 } | |
198 | |
176 if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth) | 199 if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth) |
177 wp->w_width = wp->w_minwidth; | 200 wp->w_width = wp->w_minwidth; |
178 if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth) | 201 if (wp->w_width > maxwidth) |
179 wp->w_width = wp->w_maxwidth; | 202 wp->w_width = maxwidth; |
180 if (wp->w_width > Columns - wp->w_wincol) | |
181 wp->w_width = Columns - wp->w_wincol; | |
182 | 203 |
183 if (wp->w_height <= 1) | 204 if (wp->w_height <= 1) |
184 // TODO: adjust height for wrapped lines | 205 wp->w_height = wp->w_buffer->b_ml.ml_line_count + wrapped; |
185 wp->w_height = wp->w_buffer->b_ml.ml_line_count; | |
186 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) | 206 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) |
187 wp->w_height = wp->w_minheight; | 207 wp->w_height = wp->w_minheight; |
188 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) | 208 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) |
189 wp->w_height = wp->w_maxheight; | 209 wp->w_height = wp->w_maxheight; |
190 if (wp->w_height > Rows - wp->w_winrow) | 210 if (wp->w_height > Rows - wp->w_winrow) |