summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.1406
blob: a115ee6c0e57a8bf5896fc11c5a35f16932d1ca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
To: vim_dev@googlegroups.com
Subject: Patch 8.1.1406
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.1406
Problem:    popup_hide() and popup_show() not implemented yet.
Solution:   Implement the functions.
Files:	    src/popupwin.c, src/proto/popupwin.pro, src/evalfunc.c,
            src/structs.h, runtime/doc/popup.txt, src/screen.c, src/vim.h,
            src/testdir/test_popupwin.vim


*** ../vim-8.1.1405/src/popupwin.c	2019-05-26 21:03:19.940073927 +0200
--- src/popupwin.c	2019-05-26 22:04:53.509693725 +0200
***************
*** 195,212 ****
  }
  
  /*
   * popup_close({id})
   */
      void
  f_popup_close(typval_T *argvars, typval_T *rettv UNUSED)
  {
!     int		nr = (int)tv_get_number(argvars);
  
!     popup_close(nr);
  }
  
      static void
! popup_undisplay(win_T *wp)
  {
      if (wp->w_winrow + wp->w_height >= cmdline_row)
  	clear_cmdline = TRUE;
--- 195,279 ----
  }
  
  /*
+  * Find the popup window with window-ID "id".
+  * If the popup window does not exist NULL is returned.
+  * If the window is not a popup window, and error message is given.
+  */
+     static win_T *
+ find_popup_win(int id)
+ {
+     win_T *wp = win_id2wp(id);
+ 
+     if (wp != NULL && !bt_popup(wp->w_buffer))
+     {
+ 	semsg(_("E993: window %d is not a popup window"), id);
+ 	return NULL;
+     }
+     return wp;
+ }
+ 
+ /*
+  * Return TRUE if there any popups that are not hidden.
+  */
+     int
+ popup_any_visible(void)
+ {
+     win_T *wp;
+ 
+     for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+ 	if ((wp->w_popup_flags & PFL_HIDDEN) == 0)
+ 	    return TRUE;
+     for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+ 	if ((wp->w_popup_flags & PFL_HIDDEN) == 0)
+ 	    return TRUE;
+     return FALSE;
+ }
+ 
+ /*
   * popup_close({id})
   */
      void
  f_popup_close(typval_T *argvars, typval_T *rettv UNUSED)
  {
!     int		id = (int)tv_get_number(argvars);
! 
!     popup_close(id);
! }
! 
! /*
!  * popup_hide({id})
!  */
!     void
! f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED)
! {
!     int		id = (int)tv_get_number(argvars);
!     win_T	*wp = find_popup_win(id);
! 
!     if (wp != NULL && (wp->w_popup_flags & PFL_HIDDEN) == 0)
!     {
! 	wp->w_popup_flags |= PFL_HIDDEN;
! 	redraw_all_later(NOT_VALID);
!     }
! }
! 
! /*
!  * popup_show({id})
!  */
!     void
! f_popup_show(typval_T *argvars, typval_T *rettv UNUSED)
! {
!     int		id = (int)tv_get_number(argvars);
!     win_T	*wp = find_popup_win(id);
  
!     if (wp != NULL && (wp->w_popup_flags & PFL_HIDDEN) != 0)
!     {
! 	wp->w_popup_flags &= ~PFL_HIDDEN;
! 	redraw_all_later(NOT_VALID);
!     }
  }
  
      static void
! popup_free(win_T *wp)
  {
      if (wp->w_winrow + wp->w_height >= cmdline_row)
  	clear_cmdline = TRUE;
***************
*** 232,238 ****
  		first_popupwin = wp->w_next;
  	    else
  		prev->w_next = wp->w_next;
! 	    popup_undisplay(wp);
  	    return;
  	}
  
--- 299,305 ----
  		first_popupwin = wp->w_next;
  	    else
  		prev->w_next = wp->w_next;
! 	    popup_free(wp);
  	    return;
  	}
  
***************
*** 258,264 ****
  		*root = wp->w_next;
  	    else
  		prev->w_next = wp->w_next;
! 	    popup_undisplay(wp);
  	    return;
  	}
  }
--- 325,331 ----
  		*root = wp->w_next;
  	    else
  		prev->w_next = wp->w_next;
! 	    popup_free(wp);
  	    return;
  	}
  }
*** ../vim-8.1.1405/src/proto/popupwin.pro	2019-05-26 14:10:59.909979018 +0200
--- src/proto/popupwin.pro	2019-05-26 21:58:55.451508950 +0200
***************
*** 1,6 ****
--- 1,9 ----
  /* popupwin.c */
  void f_popup_create(typval_T *argvars, typval_T *rettv);
+ int popup_any_visible(void);
  void f_popup_close(typval_T *argvars, typval_T *rettv);
+ void f_popup_hide(typval_T *argvars, typval_T *rettv);
+ void f_popup_show(typval_T *argvars, typval_T *rettv);
  void popup_close(int id);
  void popup_close_tabpage(tabpage_T *tp, int id);
  void close_all_popups(void);
*** ../vim-8.1.1405/src/evalfunc.c	2019-05-25 20:21:24.669951062 +0200
--- src/evalfunc.c	2019-05-26 21:49:46.478291418 +0200
***************
*** 810,815 ****
--- 810,817 ----
  #ifdef FEAT_TEXT_PROP
      {"popup_close",	1, 1, f_popup_close},
      {"popup_create",	2, 2, f_popup_create},
+     {"popup_hide",	1, 1, f_popup_hide},
+     {"popup_show",	1, 1, f_popup_show},
  #endif
  #ifdef FEAT_FLOAT
      {"pow",		2, 2, f_pow},
*** ../vim-8.1.1405/src/structs.h	2019-05-26 20:44:07.105974009 +0200
--- src/structs.h	2019-05-26 21:54:20.348903421 +0200
***************
*** 2871,2876 ****
--- 2871,2877 ----
      int		w_vsep_width;	    /* Number of separator columns (0 or 1). */
      pos_save_T	w_save_cursor;	    /* backup of cursor pos and topline */
  #ifdef FEAT_TEXT_PROP
+     int		w_popup_flags;	    // PFL_ values
      int		w_zindex;
      int		w_maxheight;	    // "maxheight" for popup window
      int		w_maxwidth;	    // "maxwidth" for popup window
*** ../vim-8.1.1405/runtime/doc/popup.txt	2019-05-26 21:03:19.940073927 +0200
--- runtime/doc/popup.txt	2019-05-26 22:12:05.835383172 +0200
***************
*** 25,31 ****
  popup window like with regular windows.
  
  A popup window can be used for such things as:
! - briefly show a message without changing the command line
  - prompt the user with a dialog
  - display contextual information while typing
  - give extra information for auto-completion
--- 25,31 ----
  popup window like with regular windows.
  
  A popup window can be used for such things as:
! - briefly show a message without overwriting the command line
  - prompt the user with a dialog
  - display contextual information while typing
  - give extra information for auto-completion
***************
*** 42,52 ****
  
  A popup window has a window-ID like other windows, but behaves differently.
  The size can be up to the whole Vim window and it overlaps other windows.
! It contains a buffer, and that buffer is always associated with the popup
! window.  The window cannot be used in Normal, Visual or Insert mode, it does
! not get keyboard focus.  You can use functions like `setbufline()` to change
! the text in the buffer.  There are more differences from how this window and
! buffer behave compared to regular windows and buffers, see |popup-buffer|.
  
  If this is not what you are looking for, check out other popup functionality:
  - popup menu, see |popup-menu|
--- 42,55 ----
  
  A popup window has a window-ID like other windows, but behaves differently.
  The size can be up to the whole Vim window and it overlaps other windows.
! Popup windows can also overlap each other.
! 
! The popup window contains a buffer, and that buffer is always associated with
! the popup window.  The window cannot be used in Normal, Visual or Insert mode,
! it does not get keyboard focus.  You can use functions like `setbufline()` to
! change the text in the buffer.  There are more differences from how this
! window and buffer behave compared to regular windows and buffers, see
! |popup-buffer|.
  
  If this is not what you are looking for, check out other popup functionality:
  - popup menu, see |popup-menu|
***************
*** 55,63 ****
  
  WINDOW POSITION AND SIZE			*popup-position*
  
! The height of the window is normally equal to the number of lines in the
! buffer.  It can be limited with the "maxheight" property.  You can use empty
! lines to increase the height.
  
  The width of the window is normally equal to the longest line in the buffer.
  It can be limited with the "maxwidth" property.  You can use spaces to
--- 58,66 ----
  
  WINDOW POSITION AND SIZE			*popup-position*
  
! The height of the window is normally equal to the number of, possibly
! wrapping, lines in the buffer.  It can be limited with the "maxheight"
! property.  You can use empty lines to increase the height.
  
  The width of the window is normally equal to the longest line in the buffer.
  It can be limited with the "maxwidth" property.  You can use spaces to
***************
*** 81,91 ****
  
  IMPLEMENTATION:
  - Code is in popupwin.c
! - handle screen resize in screenalloc().
! - Support tab-local popup windows, use tp_first_popupwin and
!   first_tab_popupwin.  Swap like with firstwin/curwin.
  - Make redrawing more efficient and avoid flicker.
! - implement all the unimplemented features.
  
  
  ==============================================================================
--- 84,95 ----
  
  IMPLEMENTATION:
  - Code is in popupwin.c
! - Implement list of lines with text properties
! - Implement filter.
! - Handle screen resize in screenalloc().
  - Make redrawing more efficient and avoid flicker.
! - Properly figure out the size and position.
! - Implement all the unimplemented options and features.
  
  
  ==============================================================================
***************
*** 93,101 ****
  
  THIS IS UNDER DESIGN - ANYTHING MAY STILL CHANGE  
  
! Proposal and discussion on issue #4063: https://github.com/vim/vim/issues/4063
! 
! [functions to be moved to eval.txt later, keep list of functions here]
  
  popup_create({text}, {options})				*popup_create()*
  		Open a popup window showing {text}, which is either:
--- 97,103 ----
  
  THIS IS UNDER DESIGN - ANYTHING MAY STILL CHANGE  
  
! [functions to be moved to eval.txt later, keep overview of functions here]
  
  popup_create({text}, {options})				*popup_create()*
  		Open a popup window showing {text}, which is either:
***************
*** 176,190 ****
  		"callback" to a function that handles the selected item.
  
  
- popup_show({id})						*popup_show()*
- 	  	{not implemented yet}
- 		If {id} is a hidden popup, show it now.
- 
  popup_hide({id})						*popup_hide()*
- 	  	{not implemented yet}
  		If {id} is a displayed popup, hide it now. If the popup has a
  		filter it will not be invoked for so long as the popup is
  		hidden.
  
  popup_move({id}, {options})					*popup_move()*
  	  	{not implemented yet}
--- 178,193 ----
  		"callback" to a function that handles the selected item.
  
  
  popup_hide({id})						*popup_hide()*
  		If {id} is a displayed popup, hide it now. If the popup has a
  		filter it will not be invoked for so long as the popup is
  		hidden.
+ 		If window {id} does not exist nothing happens.  If window {id}
+ 		exists but is not a popup window an error is given. *E993*
+ 
+ popup_show({id})						*popup_show()*
+ 		If {id} is a hidden popup, show it now.
+ 		For {id} see `popup_hide()`.
  
  popup_move({id}, {options})					*popup_move()*
  	  	{not implemented yet}
***************
*** 192,197 ****
--- 195,201 ----
  		{options} may contain the items from |popup_create()| that
  		specify the popup position: "line", "col", "pos", "maxheight",
  		"minheight", "maxwidth" and "minwidth".
+ 		For {id} see `popup_hide()`.
  
  
  popup_filter_menu({id}, {key})				*popup_filter_menu()*
***************
*** 257,262 ****
--- 261,269 ----
  - 'undolevels' is -1: no undo at all
  TODO: more
  
+ It is possible to change these options, but anything might break then, so
+ better leave them alone.
+ 
  The window does have a cursor position, but the cursor is not displayed.
  
  Options can be set on the window with `setwinvar()`, e.g.: >
*** ../vim-8.1.1405/src/screen.c	2019-05-26 18:48:09.406542616 +0200
--- src/screen.c	2019-05-26 21:57:18.544000198 +0200
***************
*** 610,616 ****
      }
  #ifdef FEAT_TEXT_PROP
      // TODO: avoid redrawing everything when there is a popup window.
!     if (first_popupwin != NULL || curtab->tp_first_popupwin != NULL)
  	type = NOT_VALID;
  #endif
  
--- 610,616 ----
      }
  #ifdef FEAT_TEXT_PROP
      // TODO: avoid redrawing everything when there is a popup window.
!     if (popup_any_visible())
  	type = NOT_VALID;
  #endif
  
***************
*** 999,1007 ****
  
      // Reset all the VALID_POPUP flags.
      for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
! 	wp->w_valid &= ~VALID_POPUP;
      for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
! 	wp->w_valid &= ~VALID_POPUP;
  
      // TODO: don't redraw every popup every time.
      for (;;)
--- 999,1007 ----
  
      // Reset all the VALID_POPUP flags.
      for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
! 	wp->w_popup_flags &= ~PFL_REDRAWN;
      for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
! 	wp->w_popup_flags &= ~PFL_REDRAWN;
  
      // TODO: don't redraw every popup every time.
      for (;;)
***************
*** 1012,1025 ****
  	lowest_zindex = INT_MAX;
  	lowest_wp = NULL;
  	for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
! 	    if ((wp->w_valid & VALID_POPUP) == 0
  					       && wp->w_zindex < lowest_zindex)
  	    {
  		lowest_zindex = wp->w_zindex;
  		lowest_wp = wp;
  	    }
  	for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
! 	    if ((wp->w_valid & VALID_POPUP) == 0
  					       && wp->w_zindex < lowest_zindex)
  	    {
  		lowest_zindex = wp->w_zindex;
--- 1012,1025 ----
  	lowest_zindex = INT_MAX;
  	lowest_wp = NULL;
  	for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
! 	    if ((wp->w_popup_flags & (PFL_REDRAWN|PFL_HIDDEN)) == 0
  					       && wp->w_zindex < lowest_zindex)
  	    {
  		lowest_zindex = wp->w_zindex;
  		lowest_wp = wp;
  	    }
  	for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
! 	    if ((wp->w_popup_flags & (PFL_REDRAWN|PFL_HIDDEN)) == 0
  					       && wp->w_zindex < lowest_zindex)
  	    {
  		lowest_zindex = wp->w_zindex;
***************
*** 1029,1035 ****
  	if (lowest_wp == NULL)
  	    break;
  	win_update(lowest_wp);
! 	lowest_wp->w_valid |= VALID_POPUP;
      }
  }
  #endif
--- 1029,1035 ----
  	if (lowest_wp == NULL)
  	    break;
  	win_update(lowest_wp);
! 	lowest_wp->w_popup_flags |= PFL_REDRAWN;
      }
  }
  #endif
*** ../vim-8.1.1405/src/vim.h	2019-05-25 19:51:03.780408437 +0200
--- src/vim.h	2019-05-26 21:54:44.096783074 +0200
***************
*** 612,618 ****
  #define VALID_BOTLINE	0x20	// w_botine and w_empty_rows are valid
  #define VALID_BOTLINE_AP 0x40	// w_botine is approximated
  #define VALID_TOPLINE	0x80	// w_topline is valid (for cursor position)
! #define VALID_POPUP	0x100	// popup has been redrawn
  
  /*
   * Terminal highlighting attribute bits.
--- 612,621 ----
  #define VALID_BOTLINE	0x20	// w_botine and w_empty_rows are valid
  #define VALID_BOTLINE_AP 0x40	// w_botine is approximated
  #define VALID_TOPLINE	0x80	// w_topline is valid (for cursor position)
! 
! // Values for w_popup_flags.
! #define PFL_HIDDEN	1	// popup is not displayed
! #define PFL_REDRAWN	2	// popup was just redrawn
  
  /*
   * Terminal highlighting attribute bits.
*** ../vim-8.1.1405/src/testdir/test_popupwin.vim	2019-05-26 21:03:19.940073927 +0200
--- src/testdir/test_popupwin.vim	2019-05-26 22:13:41.802400120 +0200
***************
*** 76,78 ****
--- 76,116 ----
  
    bwipe!
  endfunc
+ 
+ func Test_popup_hide()
+   topleft vnew
+   call setline(1, 'hello')
+ 
+   let winid = popup_create('world', {
+ 	\ 'line': 1,
+ 	\ 'col': 1,
+ 	\})
+   redraw
+   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
+   call assert_equal('world', line)
+ 
+   call popup_hide(winid)
+   redraw
+   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
+   call assert_equal('hello', line)
+ 
+   call popup_show(winid)
+   redraw
+   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
+   call assert_equal('world', line)
+ 
+ 
+   call popup_close(winid)
+   redraw
+   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
+   call assert_equal('hello', line)
+ 
+   " error is given for existing non-popup window
+   call assert_fails('call popup_hide(win_getid())', 'E993:')
+ 
+   " no error non-existing window
+   call popup_hide(1234234)
+   call popup_show(41234234)
+ 
+   bwipe!
+ endfunc
*** ../vim-8.1.1405/src/version.c	2019-05-26 21:03:19.940073927 +0200
--- src/version.c	2019-05-26 22:13:59.338228662 +0200
***************
*** 769,770 ****
--- 769,772 ----
  {   /* Add new patch number below this line */
+ /**/
+     1406,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
36. You miss more than five meals a week downloading the latest games from
    Apogee.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///