Mercurial > vim
comparison src/popupwin.c @ 17051:221d4b82bc0b v8.1.1525
patch 8.1.1525: cannot move a popup window with the mouse
commit https://github.com/vim/vim/commit/b53fb31a1e27a806396e38592055cfb3ebf43cf9
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 13 23:59:52 2019 +0200
patch 8.1.1525: cannot move a popup window with the mouse
Problem: Cannot move a popup window with the mouse.
Solution: Add the "drag" property and make it possible to drag a popup
window by its border.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 14 Jun 2019 00:00:08 +0200 |
parents | 6400d1ad5e4b |
children | f4de7ccdfd8c |
comparison
equal
deleted
inserted
replaced
17050:f7293a729741 | 17051:221d4b82bc0b |
---|---|
162 wp->w_popup_mincol = (int)(ptr - ml_get_curline()); | 162 wp->w_popup_mincol = (int)(ptr - ml_get_curline()); |
163 wp->w_popup_maxcol = wp->w_popup_mincol + len - 1; | 163 wp->w_popup_maxcol = wp->w_popup_mincol + len - 1; |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 /* | |
168 * Return TRUE if "row"/"col" is on the border of the popup. | |
169 * The values are relative to the top-left corner. | |
170 */ | |
171 int | |
172 popup_on_border(win_T *wp, int row, int col) | |
173 { | |
174 return (row == 0 && wp->w_popup_border[0] > 0) | |
175 || (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0) | |
176 || (col == 0 && wp->w_popup_border[3] > 0) | |
177 || (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0); | |
178 } | |
179 | |
180 // Values set when dragging a popup window starts. | |
181 static int drag_start_row; | |
182 static int drag_start_col; | |
183 static int drag_start_wantline; | |
184 static int drag_start_wantcol; | |
185 | |
186 /* | |
187 * Mouse down on border of popup window: start dragging it. | |
188 * Uses mouse_col and mouse_row. | |
189 */ | |
190 void | |
191 popup_start_drag(win_T *wp) | |
192 { | |
193 drag_start_row = mouse_row; | |
194 drag_start_col = mouse_col; | |
195 // TODO: handle using different corner | |
196 if (wp->w_wantline == 0) | |
197 drag_start_wantline = wp->w_winrow + 1; | |
198 else | |
199 drag_start_wantline = wp->w_wantline; | |
200 if (wp->w_wantcol == 0) | |
201 drag_start_wantcol = wp->w_wincol + 1; | |
202 else | |
203 drag_start_wantcol = wp->w_wantcol; | |
204 } | |
205 | |
206 /* | |
207 * Mouse moved while dragging a popup window: adjust the window popup position. | |
208 */ | |
209 void | |
210 popup_drag(win_T *wp) | |
211 { | |
212 // The popup may be closed before dragging stops. | |
213 if (!win_valid_popup(wp)) | |
214 return; | |
215 | |
216 wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); | |
217 if (wp->w_wantline < 1) | |
218 wp->w_wantline = 1; | |
219 if (wp->w_wantline > Rows) | |
220 wp->w_wantline = Rows; | |
221 wp->w_wantcol = drag_start_wantcol + (mouse_col - drag_start_col); | |
222 if (wp->w_wantcol < 1) | |
223 wp->w_wantcol = 1; | |
224 if (wp->w_wantcol > Columns) | |
225 wp->w_wantcol = Columns; | |
226 | |
227 popup_adjust_position(wp); | |
228 } | |
167 | 229 |
168 #if defined(FEAT_TIMERS) | 230 #if defined(FEAT_TIMERS) |
169 static void | 231 static void |
170 popup_add_timeout(win_T *wp, int time) | 232 popup_add_timeout(win_T *wp, int time) |
171 { | 233 { |
234 if (di != NULL) | 296 if (di != NULL) |
235 { | 297 { |
236 nr = dict_get_number(dict, (char_u *)"wrap"); | 298 nr = dict_get_number(dict, (char_u *)"wrap"); |
237 wp->w_p_wrap = nr != 0; | 299 wp->w_p_wrap = nr != 0; |
238 } | 300 } |
301 | |
302 wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag"); | |
239 | 303 |
240 di = dict_find(dict, (char_u *)"callback", -1); | 304 di = dict_find(dict, (char_u *)"callback", -1); |
241 if (di != NULL) | 305 if (di != NULL) |
242 { | 306 { |
243 callback_T callback = get_callback(&di->di_tv); | 307 callback_T callback = get_callback(&di->di_tv); |
796 wp->w_popup_border[i] = 1; | 860 wp->w_popup_border[i] = 1; |
797 wp->w_popup_padding[1] = 1; | 861 wp->w_popup_padding[1] = 1; |
798 wp->w_popup_padding[3] = 1; | 862 wp->w_popup_padding[3] = 1; |
799 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, | 863 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
800 (char_u *)"WarningMsg", OPT_FREE|OPT_LOCAL, 0); | 864 (char_u *)"WarningMsg", OPT_FREE|OPT_LOCAL, 0); |
865 wp->w_popup_drag = 1; | |
801 } | 866 } |
802 | 867 |
803 // Deal with options. | 868 // Deal with options. |
804 apply_options(wp, buf, argvars[1].vval.v_dict); | 869 apply_options(wp, buf, argvars[1].vval.v_dict); |
805 | 870 |