annotate src/popupmnu.c @ 17809:59f8948b7590 v8.1.1901

patch 8.1.1901: the +insert_expand feature is not always available Commit: https://github.com/vim/vim/commit/e2c453d38f6512ac4cff7cd26aa7780b4e2534d7 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 21 14:37:09 2019 +0200 patch 8.1.1901: the +insert_expand feature is not always available Problem: The +insert_expand feature is not always available. Solution: Graduate the +insert_expand feature.
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Aug 2019 14:45:04 +0200
parents 87c5c07a4cac
children b5499bf22a97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 8220
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
2 *
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
4 *
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
8 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
9
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
10 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
11 * popupmnu.c: Popup menu (PUM)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
12 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
13 #include "vim.h"
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
14
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
15 static pumitem_T *pum_array = NULL; /* items of displayed pum */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
16 static int pum_size; /* nr of items in "pum_array" */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
17 static int pum_selected; /* index of selected item or -1 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
18 static int pum_first = 0; /* index of top item */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
19
15521
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
20 static int call_update_screen = FALSE;
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
21
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
22 static int pum_height; /* nr of displayed pum items */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
23 static int pum_width; /* width of displayed pum items */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
24 static int pum_base_width; /* width of pum items base */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
25 static int pum_kind_width; /* width of pum items kind column */
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
26 static int pum_extra_width; /* width of extra stuff */
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
27 static int pum_scrollbar; /* TRUE when scrollbar present */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
28
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
29 static int pum_row; /* top row of pum */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
30 static int pum_col; /* left column of pum */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
31
14095
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
32 static win_T *pum_window = NULL;
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
33 static int pum_win_row;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
34 static int pum_win_height;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
35 static int pum_win_col;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
36 static int pum_win_wcol;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
37 static int pum_win_width;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
38
15521
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
39 static int pum_do_redraw = FALSE; // do redraw anyway
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
40 static int pum_skip_redraw = FALSE; // skip redraw
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
41
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7181
diff changeset
42 static int pum_set_selected(int n, int repeat);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
43
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
44 #define PUM_DEF_HEIGHT 10
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
45
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
46 static void
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
47 pum_compute_size(void)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
48 {
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
49 int i;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
50 int w;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
51
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
52 /* Compute the width of the widest match and the widest extra. */
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
53 pum_base_width = 0;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
54 pum_kind_width = 0;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
55 pum_extra_width = 0;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
56 for (i = 0; i < pum_size; ++i)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
57 {
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
58 w = vim_strsize(pum_array[i].pum_text);
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
59 if (pum_base_width < w)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
60 pum_base_width = w;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
61 if (pum_array[i].pum_kind != NULL)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
62 {
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
63 w = vim_strsize(pum_array[i].pum_kind) + 1;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
64 if (pum_kind_width < w)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
65 pum_kind_width = w;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
66 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
67 if (pum_array[i].pum_extra != NULL)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
68 {
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
69 w = vim_strsize(pum_array[i].pum_extra) + 1;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
70 if (pum_extra_width < w)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
71 pum_extra_width = w;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
72 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
73 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
74 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
75
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
76 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
77 * Show the popup menu with items "array[size]".
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
78 * "array" must remain valid until pum_undisplay() is called!
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
79 * When possible the leftmost character is aligned with cursor column.
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
80 * The menu appears above the screen line "row" or at "row" + "height" - 1.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
81 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
82 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
83 pum_display(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
84 pumitem_T *array,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
85 int size,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
86 int selected) /* index of initially selected item, none if
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
87 out of range */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
88 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
89 int def_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
90 int max_width;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
91 int context_lines;
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
92 int cursor_col;
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
93 int above_row;
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
94 int below_row;
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
95 int redo_count = 0;
12477
68d7bc045dbe patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
96 #if defined(FEAT_QUICKFIX)
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
97 win_T *pvwin;
10332
4d98f501d1c5 commit https://github.com/vim/vim/commit/aab3383e70456f054fe9d0963fe3eb45994aa5e7
Christian Brabandt <cb@256bit.org>
parents: 10326
diff changeset
98 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
99
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
100 do
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
101 {
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
102 def_width = p_pw;
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
103 above_row = 0;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
104 below_row = cmdline_row;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
105
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
106 /* Pretend the pum is already there to avoid that must_redraw is set
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
107 * when 'cuc' is on. */
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
108 pum_array = (pumitem_T *)1;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
109 validate_cursor_col();
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
110 pum_array = NULL;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
111
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
112 // Remember the essential parts of the window position and size, so we
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
113 // can decide when to reposition the popup menu.
14095
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
114 pum_window = curwin;
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
115 pum_win_row = curwin->w_wrow + W_WINROW(curwin);
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
116 pum_win_height = curwin->w_height;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
117 pum_win_col = curwin->w_wincol;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
118 pum_win_wcol = curwin->w_wcol;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
119 pum_win_width = curwin->w_width;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
120
12477
68d7bc045dbe patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
121 #if defined(FEAT_QUICKFIX)
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
122 FOR_ALL_WINDOWS(pvwin)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
123 if (pvwin->w_p_pvw)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
124 break;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
125 if (pvwin != NULL)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
126 {
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
127 if (W_WINROW(pvwin) < W_WINROW(curwin))
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
128 above_row = W_WINROW(pvwin) + pvwin->w_height;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
129 else if (W_WINROW(pvwin) > W_WINROW(curwin) + curwin->w_height)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
130 below_row = W_WINROW(pvwin);
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
131 }
8220
ad9edad64d22 commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
132 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
133
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
134 /*
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
135 * Figure out the size and position of the pum.
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
136 */
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
137 if (size < PUM_DEF_HEIGHT)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
138 pum_height = size;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
139 else
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
140 pum_height = PUM_DEF_HEIGHT;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
141 if (p_ph > 0 && pum_height > p_ph)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
142 pum_height = p_ph;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
143
14685
17a7d9e71ebb patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents: 14095
diff changeset
144 /* Put the pum below "pum_win_row" if possible. If there are few lines
17a7d9e71ebb patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents: 14095
diff changeset
145 * decide on where there is more room. */
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
146 if (pum_win_row + 2 >= below_row - pum_height
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
147 && pum_win_row - above_row > (below_row - above_row) / 2)
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
148 {
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
149 /* pum above "pum_win_row" */
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
150
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
151 /* Leave two lines of context if possible */
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
152 if (curwin->w_wrow - curwin->w_cline_row >= 2)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
153 context_lines = 2;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
154 else
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
155 context_lines = curwin->w_wrow - curwin->w_cline_row;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
156
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
157 if (pum_win_row >= size + context_lines)
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
158 {
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
159 pum_row = pum_win_row - size - context_lines;
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
160 pum_height = size;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
161 }
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
162 else
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
163 {
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
164 pum_row = 0;
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
165 pum_height = pum_win_row - context_lines;
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
166 }
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
167 if (p_ph > 0 && pum_height > p_ph)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
168 {
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
169 pum_row += pum_height - p_ph;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
170 pum_height = p_ph;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
171 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
172 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
173 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
174 {
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
175 /* pum below "pum_win_row" */
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
176
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
177 /* Leave two lines of context if possible */
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
178 if (curwin->w_cline_row
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
179 + curwin->w_cline_height - curwin->w_wrow >= 3)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
180 context_lines = 3;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
181 else
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
182 context_lines = curwin->w_cline_row
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
183 + curwin->w_cline_height - curwin->w_wrow;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
184
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
185 pum_row = pum_win_row + context_lines;
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
186 if (size > below_row - pum_row)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
187 pum_height = below_row - pum_row;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
188 else
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
189 pum_height = size;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
190 if (p_ph > 0 && pum_height > p_ph)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
191 pum_height = p_ph;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
192 }
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
193
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
194 /* don't display when we only have room for one line */
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
195 if (pum_height < 1 || (pum_height == 1 && size > 1))
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
196 return;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
197
12477
68d7bc045dbe patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
198 #if defined(FEAT_QUICKFIX)
15087
6a74cde86252 patch 8.1.0554: popup menu overlaps with preview window
Bram Moolenaar <Bram@vim.org>
parents: 14952
diff changeset
199 // If there is a preview window above avoid drawing over it.
6a74cde86252 patch 8.1.0554: popup menu overlaps with preview window
Bram Moolenaar <Bram@vim.org>
parents: 14952
diff changeset
200 if (pvwin != NULL && pum_row < above_row && pum_height > above_row)
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
201 {
15087
6a74cde86252 patch 8.1.0554: popup menu overlaps with preview window
Bram Moolenaar <Bram@vim.org>
parents: 14952
diff changeset
202 pum_row = above_row;
6a74cde86252 patch 8.1.0554: popup menu overlaps with preview window
Bram Moolenaar <Bram@vim.org>
parents: 14952
diff changeset
203 pum_height = pum_win_row - above_row;
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
204 }
8220
ad9edad64d22 commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
205 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
206
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
207 pum_array = array;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
208 pum_size = size;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
209 pum_compute_size();
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
210 max_width = pum_base_width;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
211
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
212 /* Calculate column */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
213 #ifdef FEAT_RIGHTLEFT
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
214 if (curwin->w_p_rl)
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
215 cursor_col = curwin->w_wincol + curwin->w_width
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
216 - curwin->w_wcol - 1;
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
217 else
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
218 #endif
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
219 cursor_col = curwin->w_wincol + curwin->w_wcol;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
220
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
221 /* if there are more items than room we need a scrollbar */
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
222 if (pum_height < size)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
223 {
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
224 pum_scrollbar = 1;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
225 ++max_width;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
226 }
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
227 else
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
228 pum_scrollbar = 0;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
229
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
230 if (def_width < max_width)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
231 def_width = max_width;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
232
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
233 if (((cursor_col < Columns - p_pw
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
234 || cursor_col < Columns - max_width)
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
235 #ifdef FEAT_RIGHTLEFT
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
236 && !curwin->w_p_rl)
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
237 || (curwin->w_p_rl
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
238 && (cursor_col > p_pw || cursor_col > max_width)
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
239 #endif
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
240 ))
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
241 {
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
242 /* align pum with "cursor_col" */
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
243 pum_col = cursor_col;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
244
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
245 /* start with the maximum space available */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
246 #ifdef FEAT_RIGHTLEFT
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
247 if (curwin->w_p_rl)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
248 pum_width = pum_col - pum_scrollbar + 1;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
249 else
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
250 #endif
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
251 pum_width = Columns - pum_col - pum_scrollbar;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
252
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
253 if (pum_width > max_width + pum_kind_width + pum_extra_width + 1
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
254 && pum_width > p_pw)
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
255 {
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
256 /* the width is more than needed for the items, make it
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
257 * narrower */
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
258 pum_width = max_width + pum_kind_width + pum_extra_width + 1;
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
259 if (pum_width < p_pw)
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
260 pum_width = p_pw;
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
261 }
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
262 else if (((cursor_col > p_pw || cursor_col > max_width)
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
263 #ifdef FEAT_RIGHTLEFT
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
264 && !curwin->w_p_rl)
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
265 || (curwin->w_p_rl && (cursor_col < Columns - p_pw
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
266 || cursor_col < Columns - max_width)
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
267 #endif
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
268 ))
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
269 {
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
270 /* align pum edge with "cursor_col" */
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
271 #ifdef FEAT_RIGHTLEFT
13296
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
272 if (curwin->w_p_rl
13328
2c639a9a4def patch 8.0.1538: popupmenu is too far left when completion is long
Christian Brabandt <cb@256bit.org>
parents: 13296
diff changeset
273 && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1)
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
274 {
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
275 pum_col = cursor_col + max_width + pum_scrollbar + 1;
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
276 if (pum_col >= Columns)
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
277 pum_col = Columns - 1;
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
278 }
13296
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
279 else if (!curwin->w_p_rl)
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
280 #endif
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
281 {
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
282 if (curwin->w_wincol > Columns - max_width - pum_scrollbar
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
283 && max_width <= p_pw)
13296
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
284 {
13331
1ba4f926247c patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents: 13328
diff changeset
285 /* use full width to end of the screen */
13296
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
286 pum_col = Columns - max_width - pum_scrollbar;
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
287 if (pum_col < 0)
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
288 pum_col = 0;
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
289 }
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
290 }
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
291
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
292 #ifdef FEAT_RIGHTLEFT
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
293 if (curwin->w_p_rl)
13296
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
294 pum_width = pum_col - pum_scrollbar + 1;
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
295 else
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
296 #endif
13296
67345bc7fe31 patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
297 pum_width = Columns - pum_col - pum_scrollbar;
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
298
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
299 if (pum_width < p_pw)
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
300 {
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
301 pum_width = p_pw;
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
302 #ifdef FEAT_RIGHTLEFT
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
303 if (curwin->w_p_rl)
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
304 {
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
305 if (pum_width > pum_col)
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
306 pum_width = pum_col;
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
307 }
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
308 else
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
309 #endif
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
310 {
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
311 if (pum_width >= Columns - pum_col)
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
312 pum_width = Columns - pum_col - 1;
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
313 }
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
314 }
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
315 else if (pum_width > max_width + pum_kind_width
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
316 + pum_extra_width + 1
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
317 && pum_width > p_pw)
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
318 {
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
319 pum_width = max_width + pum_kind_width
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
320 + pum_extra_width + 1;
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
321 if (pum_width < p_pw)
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
322 pum_width = p_pw;
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
323 }
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
324 }
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
325
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
326 }
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
327 else if (Columns < def_width)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
328 {
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
329 /* not enough room, will use what we have */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
330 #ifdef FEAT_RIGHTLEFT
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
331 if (curwin->w_p_rl)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
332 pum_col = Columns - 1;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
333 else
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
334 #endif
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
335 pum_col = 0;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
336 pum_width = Columns - 1;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
337 }
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
338 else
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
339 {
13242
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
340 if (max_width > p_pw)
5b0faf628a55 patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents: 13234
diff changeset
341 max_width = p_pw; /* truncate */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
342 #ifdef FEAT_RIGHTLEFT
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
343 if (curwin->w_p_rl)
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
344 pum_col = max_width - 1;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
345 else
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
346 #endif
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
347 pum_col = Columns - max_width;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
348 pum_width = max_width - pum_scrollbar;
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
349 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
350
12566
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
351 /* Set selected item and redraw. If the window size changed need to
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
352 * redo the positioning. Limit this to two times, when there is not
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
353 * much room the window size will keep changing. */
33a900199c25 patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
354 } while (pum_set_selected(selected, redo_count) && ++redo_count <= 2);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
355 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
356
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
357 /*
15521
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
358 * Set a flag that when pum_redraw() is called it first calls update_screen().
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
359 * This will avoid clearing and redrawing the popup menu, prevent flicker.
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
360 */
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
361 void
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
362 pum_call_update_screen()
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
363 {
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
364 call_update_screen = TRUE;
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
365
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
366 // Update the cursor position to be able to compute the popup menu
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
367 // position. The cursor line length may have changed because of the
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
368 // inserted completion.
15683
adc6442118b8 patch 8.1.0849: cursorline highlight is not always updated
Bram Moolenaar <Bram@vim.org>
parents: 15521
diff changeset
369 curwin->w_valid &= ~(VALID_CROW|VALID_CHEIGHT);
15521
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
370 validate_cursor();
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
371 }
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
372
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
373 /*
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
374 * Return TRUE if we are going to redraw the popup menu and the screen position
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
375 * "row"/"col" is under the popup menu.
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
376 */
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
377 int
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
378 pum_under_menu(int row, int col)
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
379 {
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
380 return pum_skip_redraw
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
381 && row >= pum_row
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
382 && row < pum_row + pum_height
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
383 && col >= pum_col - 1
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
384 && col < pum_col + pum_width;
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
385 }
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
386
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
387 /*
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
388 * Redraw the popup menu, using "pum_first" and "pum_selected".
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
389 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
390 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
391 pum_redraw(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
392 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
393 int row = pum_row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
394 int col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
395 int attr_norm = highlight_attr[HLF_PNI];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
396 int attr_select = highlight_attr[HLF_PSI];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
397 int attr_scroll = highlight_attr[HLF_PSB];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
398 int attr_thumb = highlight_attr[HLF_PST];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
399 int attr;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
400 int i;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
401 int idx;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
402 char_u *s;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
403 char_u *p = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
404 int totwidth, width, w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
405 int thumb_pos = 0;
15967
ddd82b1c9e9d patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents: 15683
diff changeset
406 int thumb_height = 1;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
407 int round;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
408 int n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
409
15521
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
410 if (call_update_screen)
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
411 {
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
412 call_update_screen = FALSE;
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
413 pum_skip_redraw = TRUE; // do not redraw in pum_may_redraw().
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
414 update_screen(0);
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
415 pum_skip_redraw = FALSE;
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
416 }
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
417
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
418 // never display more than we have
5444
d563839a9be0 updated for version 7.4.072
Bram Moolenaar <bram@vim.org>
parents: 2622
diff changeset
419 if (pum_first > pum_size - pum_height)
d563839a9be0 updated for version 7.4.072
Bram Moolenaar <bram@vim.org>
parents: 2622
diff changeset
420 pum_first = pum_size - pum_height;
d563839a9be0 updated for version 7.4.072
Bram Moolenaar <bram@vim.org>
parents: 2622
diff changeset
421
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
422 if (pum_scrollbar)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
423 {
15967
ddd82b1c9e9d patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents: 15683
diff changeset
424 thumb_height = pum_height * pum_height / pum_size;
ddd82b1c9e9d patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents: 15683
diff changeset
425 if (thumb_height == 0)
ddd82b1c9e9d patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents: 15683
diff changeset
426 thumb_height = 1;
ddd82b1c9e9d patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents: 15683
diff changeset
427 thumb_pos = (pum_first * (pum_height - thumb_height)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
428 + (pum_size - pum_height) / 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
429 / (pum_size - pum_height);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
430 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
431
16986
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
432 #ifdef FEAT_TEXT_PROP
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
433 // The popup menu is drawn over popup menus with zindex under
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
434 // POPUPMENU_ZINDEX.
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
435 screen_zindex = POPUPMENU_ZINDEX;
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
436 #endif
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
437
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
438 for (i = 0; i < pum_height; ++i)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
439 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
440 idx = i + pum_first;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
441 attr = (idx == pum_selected) ? attr_select : attr_norm;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
442
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
443 /* prepend a space if there is room */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
444 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
445 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
446 {
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12513
diff changeset
447 if (pum_col < curwin->w_wincol + curwin->w_width - 1)
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
448 screen_putchar(' ', row, pum_col + 1, attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
449 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
450 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
451 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
452 if (pum_col > 0)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
453 screen_putchar(' ', row, pum_col - 1, attr);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
454
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
455 /* Display each entry, use two spaces for a Tab.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
456 * Do this 3 times: For the main text, kind and extra info */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
457 col = pum_col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
458 totwidth = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
459 for (round = 1; round <= 3; ++round)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
460 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
461 width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
462 s = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
463 switch (round)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
464 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
465 case 1: p = pum_array[idx].pum_text; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
466 case 2: p = pum_array[idx].pum_kind; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
467 case 3: p = pum_array[idx].pum_extra; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
468 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
469 if (p != NULL)
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
470 for ( ; ; MB_PTR_ADV(p))
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
471 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
472 if (s == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
473 s = p;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
474 w = ptr2cells(p);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
475 if (*p == NUL || *p == TAB || totwidth + w > pum_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
476 {
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
477 /* Display the text that fits or comes before a Tab.
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
478 * First convert it to printable characters. */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
479 char_u *st;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
480 int saved = *p;
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
481
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
482 if (saved != NUL)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
483 *p = NUL;
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
484 st = transstr(s);
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
485 if (saved != NUL)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
486 *p = saved;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
487 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
488 if (curwin->w_p_rl)
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
489 {
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
490 if (st != NULL)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
491 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
492 char_u *rt = reverse_text(st);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
493
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
494 if (rt != NULL)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
495 {
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
496 char_u *rt_start = rt;
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
497 int size;
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
498
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
499 size = vim_strsize(rt);
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
500 if (size > pum_width)
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
501 {
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
502 do
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
503 {
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
504 size -= has_mbyte
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
505 ? (*mb_ptr2cells)(rt) : 1;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
506 MB_PTR_ADV(rt);
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
507 } while (size > pum_width);
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
508
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
509 if (size < pum_width)
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
510 {
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
511 /* Most left character requires
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
512 * 2-cells but only 1 cell is
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
513 * available on screen. Put a
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
514 * '<' on the left of the pum
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
515 * item */
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
516 *(--rt) = '<';
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
517 size++;
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
518 }
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
519 }
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
520 screen_puts_len(rt, (int)STRLEN(rt),
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
521 row, col - size + 1, attr);
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
522 vim_free(rt_start);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
523 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
524 vim_free(st);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
525 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
526 col -= width;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
527 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
528 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
529 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
530 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
531 if (st != NULL)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
532 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
533 screen_puts_len(st, (int)STRLEN(st), row, col,
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
534 attr);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
535 vim_free(st);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
536 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
537 col += width;
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
538 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
539
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
540 if (*p != TAB)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
541 break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
542
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
543 /* Display two spaces for a Tab. */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
544 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
545 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
546 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
547 screen_puts_len((char_u *)" ", 2, row, col - 1,
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
548 attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
549 col -= 2;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
550 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
551 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
552 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
553 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
554 screen_puts_len((char_u *)" ", 2, row, col, attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
555 col += 2;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
556 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
557 totwidth += 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
558 s = NULL; /* start text at next char */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
559 width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
560 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
561 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
562 width += w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
563 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
564
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
565 if (round > 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
566 n = pum_kind_width + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
567 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
568 n = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
569
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
570 /* Stop when there is nothing more to display. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
571 if (round == 3
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
572 || (round == 2 && pum_array[idx].pum_extra == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
573 || (round == 1 && pum_array[idx].pum_kind == NULL
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
574 && pum_array[idx].pum_extra == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
575 || pum_base_width + n >= pum_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
576 break;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
577 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
578 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
579 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
580 screen_fill(row, row + 1, pum_col - pum_base_width - n + 1,
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
581 col + 1, ' ', ' ', attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
582 col = pum_col - pum_base_width - n + 1;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
583 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
584 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
585 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
586 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
587 screen_fill(row, row + 1, col, pum_col + pum_base_width + n,
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
588 ' ', ' ', attr);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
589 col = pum_col + pum_base_width + n;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
590 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
591 totwidth = pum_base_width + n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
592 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
593
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
594 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
595 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
596 screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ',
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
597 ' ', attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
598 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
599 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
600 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ',
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
601 attr);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
602 if (pum_scrollbar > 0)
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
603 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
604 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
605 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
606 screen_putchar(' ', row, pum_col - pum_width,
15967
ddd82b1c9e9d patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents: 15683
diff changeset
607 i >= thumb_pos && i < thumb_pos + thumb_height
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
608 ? attr_thumb : attr_scroll);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
609 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
610 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
611 screen_putchar(' ', row, pum_col + pum_width,
15967
ddd82b1c9e9d patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents: 15683
diff changeset
612 i >= thumb_pos && i < thumb_pos + thumb_height
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
613 ? attr_thumb : attr_scroll);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
614 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
615
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
616 ++row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
617 }
16986
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
618
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
619 #ifdef FEAT_TEXT_PROP
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
620 screen_zindex = 0;
03f3a9ca2770 patch 8.1.1493: redrawing with popups is slow and causes flicker
Bram Moolenaar <Bram@vim.org>
parents: 16845
diff changeset
621 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
622 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
623
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
624 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
625 * Set the index of the currently selected item. The menu will scroll when
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
626 * necessary. When "n" is out of range don't scroll.
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
627 * This may be repeated when the preview window is used:
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
628 * "repeat" == 0: open preview window normally
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
629 * "repeat" == 1: open preview window but don't set the size
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
630 * "repeat" == 2: don't open preview window
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
631 * Returns TRUE when the window was resized and the location of the popup menu
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
632 * must be recomputed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
633 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
634 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
635 pum_set_selected(int n, int repeat)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
636 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
637 int resized = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
638 int context = pum_height / 2;
17799
87c5c07a4cac patch 8.1.1896: compiler warning for unused variable
Bram Moolenaar <Bram@vim.org>
parents: 17775
diff changeset
639 #ifdef FEAT_QUICKFIX
17775
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
640 int prev_selected = pum_selected;
17799
87c5c07a4cac patch 8.1.1896: compiler warning for unused variable
Bram Moolenaar <Bram@vim.org>
parents: 17775
diff changeset
641 #endif
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
642 #ifdef FEAT_TEXT_PROP
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
643 int has_info = FALSE;
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
644 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
645
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
646 pum_selected = n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
647
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
648 if (pum_selected >= 0 && pum_selected < pum_size)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
649 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
650 if (pum_first > pum_selected - 4)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
651 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
652 /* scroll down; when we did a jump it's probably a PageUp then
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
653 * scroll a whole page */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
654 if (pum_first > pum_selected - 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
655 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
656 pum_first -= pum_height - 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
657 if (pum_first < 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
658 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
659 else if (pum_first > pum_selected)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
660 pum_first = pum_selected;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
661 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
662 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
663 pum_first = pum_selected;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
664 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
665 else if (pum_first < pum_selected - pum_height + 5)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
666 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
667 /* scroll up; when we did a jump it's probably a PageDown then
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
668 * scroll a whole page */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
669 if (pum_first < pum_selected - pum_height + 1 + 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
670 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
671 pum_first += pum_height - 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
672 if (pum_first < pum_selected - pum_height + 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
673 pum_first = pum_selected - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
674 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
675 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
676 pum_first = pum_selected - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
677 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
678
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
679 /* Give a few lines of context when possible. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
680 if (context > 3)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
681 context = 3;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
682 if (pum_height > 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
683 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
684 if (pum_first > pum_selected - context)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
685 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
686 /* scroll down */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
687 pum_first = pum_selected - context;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
688 if (pum_first < 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
689 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
690 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
691 else if (pum_first < pum_selected + context - pum_height + 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
692 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
693 /* scroll up */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
694 pum_first = pum_selected + context - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
695 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
696 }
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
697 // adjust for the number of lines displayed
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
698 if (pum_first > pum_size - pum_height)
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
699 pum_first = pum_size - pum_height;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
700
12477
68d7bc045dbe patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
701 #if defined(FEAT_QUICKFIX)
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
702 /*
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
703 * Show extra info in the preview window if there is something and
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
704 * 'completeopt' contains "preview" or "popup".
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
705 * Skip this when tried twice already.
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
706 * Skip this also when there is not much room.
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
707 * NOTE: Be very careful not to sync undo!
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
708 */
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
709 if (pum_array[pum_selected].pum_info != NULL
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
710 && Rows > 10
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
711 && repeat <= 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
712 && vim_strchr(p_cot, 'p') != NULL)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
713 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
714 win_T *curwin_save = curwin;
12690
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12566
diff changeset
715 tabpage_T *curtab_save = curtab;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
716 int res = OK;
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
717 # ifdef FEAT_TEXT_PROP
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
718 int use_popup = strstr((char *)p_cot, "popup") != NULL;
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
719 # else
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
720 # define use_popup 0
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
721 # endif
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
722 has_info = TRUE;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
723
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
724 // Open a preview window. 3 lines by default. Prefer
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
725 // 'previewheight' if set and smaller.
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
726 g_do_tagpreview = 3;
2622
b2cfe84c96cc updated for version 7.3.044
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
727 if (p_pvh > 0 && p_pvh < g_do_tagpreview)
b2cfe84c96cc updated for version 7.3.044
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
728 g_do_tagpreview = p_pvh;
6043
a97e5b9dbc26 updated for version 7.4.361
Bram Moolenaar <bram@vim.org>
parents: 5444
diff changeset
729 ++RedrawingDisabled;
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
730 // Prevent undo sync here, if an autocommand syncs undo weird
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
731 // things can happen to the undo tree.
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
732 ++no_u_sync;
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
733 resized = prepare_tagpreview(FALSE, FALSE, use_popup);
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
734 --no_u_sync;
6043
a97e5b9dbc26 updated for version 7.4.361
Bram Moolenaar <bram@vim.org>
parents: 5444
diff changeset
735 --RedrawingDisabled;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
736 g_do_tagpreview = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
737
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
738 if (curwin->w_p_pvw
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
739 # ifdef FEAT_TEXT_PROP
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
740 || (curwin->w_popup_flags & POPF_INFO)
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
741 # endif
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
742 )
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
743 {
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
744 # ifdef FEAT_TEXT_PROP
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
745 if (use_popup)
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
746 {
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
747 int col = pum_col + pum_width + 1;
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
748
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
749 if (Columns - col < 20 && Columns - col < pum_col)
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
750 {
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
751 col = pum_col - 1;
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
752 curwin->w_popup_pos = POPPOS_TOPRIGHT;
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
753 curwin->w_maxwidth = pum_col - 1;
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
754 }
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
755 else
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
756 curwin->w_maxwidth = Columns - col + 1;
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
757 curwin->w_maxwidth -= popup_extra_width(curwin);
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
758 popup_set_wantpos_rowcol(curwin,
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
759 pum_row + pum_selected - pum_first, col);
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
760 }
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
761 # endif
10302
210af8588e8a commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
762 if (!resized
210af8588e8a commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
763 && curbuf->b_nwindows == 1
210af8588e8a commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
764 && curbuf->b_fname == NULL
17095
10e0d7d96cb0 patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents: 16986
diff changeset
765 && bt_nofile(curbuf)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
766 && curbuf->b_p_bh[0] == 'w')
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
767 {
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
768 // Already a "wipeout" buffer, make it empty.
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10410
diff changeset
769 while (!BUFEMPTY())
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
770 ml_delete((linenr_T)1, FALSE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
771 }
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
772 else
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
773 {
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
774 // Don't want to sync undo in the current buffer.
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
775 ++no_u_sync;
1743
734d5bdae499 updated for version 7.2-041
vimboss
parents: 1668
diff changeset
776 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
777 --no_u_sync;
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
778 if (res == OK)
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
779 {
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
780 // Edit a new, empty buffer. Set options for a "wipeout"
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
781 // buffer.
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
782 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
783 set_option_value((char_u *)"bt", 0L,
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
784 (char_u *)"nofile", OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
785 set_option_value((char_u *)"bh", 0L,
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
786 (char_u *)"wipe", OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
787 set_option_value((char_u *)"diff", 0L,
1302
7281a86ae640 updated for version 7.1-016
vimboss
parents: 1097
diff changeset
788 NULL, OPT_LOCAL);
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
789 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
790 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
791 if (res == OK)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
792 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
793 char_u *p, *e;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
794 linenr_T lnum = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
795
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
796 for (p = pum_array[pum_selected].pum_info; *p != NUL; )
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
797 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
798 e = vim_strchr(p, '\n');
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
799 if (e == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
800 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
801 ml_append(lnum++, p, 0, FALSE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
802 break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
803 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
804 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
805 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
806 *e = NUL;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 825
diff changeset
807 ml_append(lnum++, p, (int)(e - p + 1), FALSE);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
808 *e = '\n';
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
809 p = e + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
810 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
811 }
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
812 // delete the empty last line
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
813 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
814
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
815 /* Increase the height of the preview window to show the
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
816 * text, but no more than 'previewheight' lines. */
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
817 if (repeat == 0 && !use_popup)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
818 {
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
819 if (lnum > p_pvh)
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
820 lnum = p_pvh;
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
821 if (curwin->w_height < lnum)
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
822 {
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
823 win_setheight((int)lnum);
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
824 resized = TRUE;
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
825 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
826 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
827
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
828 curbuf->b_changed = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
829 curbuf->b_p_ma = FALSE;
17775
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
830 if (pum_selected != prev_selected)
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
831 {
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
832 # ifdef FEAT_TEXT_PROP
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
833 curwin->w_firstline = 1;
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
834 # endif
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
835 curwin->w_topline = 1;
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
836 }
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
837 else if (curwin->w_topline > curbuf->b_ml.ml_line_count)
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
838 curwin->w_topline = curbuf->b_ml.ml_line_count;
b423bd231f33 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 17767
diff changeset
839 curwin->w_cursor.lnum = curwin->w_topline;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
840 curwin->w_cursor.col = 0;
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
841 if (use_popup && win_valid(curwin_save))
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
842 redraw_win_later(curwin_save, SOME_VALID);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
843
12690
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12566
diff changeset
844 if ((curwin != curwin_save && win_valid(curwin_save))
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12566
diff changeset
845 || (curtab != curtab_save
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12566
diff changeset
846 && valid_tabpage(curtab_save)))
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
847 {
12690
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12566
diff changeset
848 if (curtab != curtab_save && valid_tabpage(curtab_save))
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12566
diff changeset
849 goto_tabpage_tp(curtab_save, FALSE, FALSE);
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12566
diff changeset
850
6089
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
851 /* When the first completion is done and the preview
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
852 * window is not resized, skip the preview window's
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
853 * status line redrawing. */
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
854 if (ins_compl_active() && !resized)
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
855 curwin->w_redr_status = FALSE;
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
856
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
857 /* Return cursor to where we were */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
858 validate_cursor();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
859 redraw_later(SOME_VALID);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
860
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
861 /* When the preview window was resized we need to
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
862 * update the view on the buffer. Only go back to
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
863 * the window when needed, otherwise it will always be
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
864 * redraw. */
17706
431d52b7f7d3 patch 8.1.1850: focus may remain in popup window
Bram Moolenaar <Bram@vim.org>
parents: 17292
diff changeset
865 if (resized && win_valid(curwin_save))
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
866 {
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
867 ++no_u_sync;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
868 win_enter(curwin_save, TRUE);
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
869 --no_u_sync;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
870 update_topline();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
871 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
872
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
873 /* Update the screen before drawing the popup menu.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
874 * Enable updating the status lines. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
875 pum_do_redraw = TRUE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
876 update_screen(0);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
877 pum_do_redraw = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
878
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
879 if (!resized && win_valid(curwin_save))
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
880 {
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
881 ++no_u_sync;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
882 win_enter(curwin_save, TRUE);
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
883 --no_u_sync;
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
884 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
885
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
886 /* May need to update the screen again when there are
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
887 * autocommands involved. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
888 pum_do_redraw = TRUE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
889 update_screen(0);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
890 pum_do_redraw = FALSE;
15521
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
891 call_update_screen = FALSE;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
892 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
893 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
894 }
17799
87c5c07a4cac patch 8.1.1896: compiler warning for unused variable
Bram Moolenaar <Bram@vim.org>
parents: 17775
diff changeset
895 # if defined(FEAT_TEXT_PROP) && defined(FEAT_QUICKFIX)
17706
431d52b7f7d3 patch 8.1.1850: focus may remain in popup window
Bram Moolenaar <Bram@vim.org>
parents: 17292
diff changeset
896 if (WIN_IS_POPUP(curwin))
431d52b7f7d3 patch 8.1.1850: focus may remain in popup window
Bram Moolenaar <Bram@vim.org>
parents: 17292
diff changeset
897 // can't keep focus in a popup window
431d52b7f7d3 patch 8.1.1850: focus may remain in popup window
Bram Moolenaar <Bram@vim.org>
parents: 17292
diff changeset
898 win_enter(firstwin, TRUE);
431d52b7f7d3 patch 8.1.1850: focus may remain in popup window
Bram Moolenaar <Bram@vim.org>
parents: 17292
diff changeset
899 # endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
900 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
901 #endif
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
902 }
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
903 #if defined(FEAT_TEXT_PROP) && defined(FEAT_QUICKFIX)
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
904 if (!has_info)
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
905 // close any popup info window
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
906 popup_close_preview(TRUE);
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
907 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
908
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
909 if (!resized)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
910 pum_redraw();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
911
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
912 return resized;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
913 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
914
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
915 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
916 * Undisplay the popup menu (later).
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
917 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
918 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
919 pum_undisplay(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
920 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
921 pum_array = NULL;
13944
ddf02a93796f patch 8.0.1842: popup menu inside terminal window isn't cleared
Christian Brabandt <cb@256bit.org>
parents: 13427
diff changeset
922 redraw_all_later(NOT_VALID);
940
306fc545fe2c updated for version 7.0-066
vimboss
parents: 838
diff changeset
923 redraw_tabline = TRUE;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
924 status_redraw_all();
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
925 #if defined(FEAT_TEXT_PROP) && defined(FEAT_QUICKFIX)
17767
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
926 // close any popup info window
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
927 popup_close_preview(TRUE);
c75da1064e33 patch 8.1.1880: cannot show extra info for completion in a popup window
Bram Moolenaar <Bram@vim.org>
parents: 17706
diff changeset
928 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
929 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
930
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
931 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
932 * Clear the popup menu. Currently only resets the offset to the first
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
933 * displayed item.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
934 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
935 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
936 pum_clear(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
937 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
938 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
939 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
940
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
941 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
942 * Return TRUE if the popup menu is displayed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
943 * Overruled when "pum_do_redraw" is set, used to redraw the status lines.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
944 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
945 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
946 pum_visible(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
947 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
948 return !pum_do_redraw && pum_array != NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
949 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
950
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
951 /*
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
952 * Reposition the popup menu to adjust for window layout changes.
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
953 */
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
954 void
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
955 pum_may_redraw(void)
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
956 {
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
957 pumitem_T *array = pum_array;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
958 int len = pum_size;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
959 int selected = pum_selected;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
960
15521
6d949e552e99 patch 8.1.0768: updating completions may cause the popup menu to flicker
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
961 if (!pum_visible() || pum_skip_redraw)
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
962 return; // nothing to do
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
963
14095
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
964 if (pum_window != curwin
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
965 || (pum_win_row == curwin->w_wrow + W_WINROW(curwin)
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
966 && pum_win_height == curwin->w_height
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
967 && pum_win_col == curwin->w_wincol
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
968 && pum_win_width == curwin->w_width))
14089
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
969 {
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
970 // window position didn't change, redraw in the same position
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
971 pum_redraw();
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
972 }
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
973 else
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
974 {
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
975 int wcol = curwin->w_wcol;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
976
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
977 // Window layout changed, recompute the position.
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
978 // Use the remembered w_wcol value, the cursor may have moved when a
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
979 // completion was inserted, but we want the menu in the same position.
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
980 pum_undisplay();
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
981 curwin->w_wcol = pum_win_wcol;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
982 curwin->w_valid |= VALID_WCOL;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
983 pum_display(array, len, selected);
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
984 curwin->w_wcol = wcol;
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
985 }
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
986 }
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
987
ae53a9274f50 patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents: 13944
diff changeset
988 /*
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
989 * Return the height of the popup menu, the number of entries visible.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
990 * Only valid when pum_visible() returns TRUE!
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
991 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
992 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
993 pum_get_height(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
994 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
995 return pum_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
996 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
997
16268
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
998 /*
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
999 * Add size information about the pum to "dict".
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1000 */
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1001 void
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1002 pum_set_event_info(dict_T *dict)
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1003 {
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1004 if (!pum_visible())
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1005 return;
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1006 dict_add_number(dict, "height", pum_height);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1007 dict_add_number(dict, "width", pum_width);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1008 dict_add_number(dict, "row", pum_row);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1009 dict_add_number(dict, "col", pum_col);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1010 dict_add_number(dict, "size", pum_size);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1011 dict_add_special(dict, "scrollbar", pum_scrollbar ? VVAL_TRUE : VVAL_FALSE);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1012 }
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
1013
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1014 #if defined(FEAT_BEVAL_TERM) || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO)
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1015 static void
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1016 pum_position_at_mouse(int min_width)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1017 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1018 if (Rows - mouse_row > pum_size)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1019 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1020 /* Enough space below the mouse row. */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1021 pum_row = mouse_row + 1;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1022 if (pum_height > Rows - pum_row)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1023 pum_height = Rows - pum_row;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1024 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1025 else
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1026 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1027 /* Show above the mouse row, reduce height if it does not fit. */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1028 pum_row = mouse_row - pum_size;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1029 if (pum_row < 0)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1030 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1031 pum_height += pum_row;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1032 pum_row = 0;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1033 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1034 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1035 if (Columns - mouse_col >= pum_base_width
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1036 || Columns - mouse_col > min_width)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1037 /* Enough space to show at mouse column. */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1038 pum_col = mouse_col;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1039 else
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1040 /* Not enough space, right align with window. */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1041 pum_col = Columns - (pum_base_width > min_width
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1042 ? min_width : pum_base_width);
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1043
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1044 pum_width = Columns - pum_col;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1045 if (pum_width > pum_base_width + 1)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1046 pum_width = pum_base_width + 1;
14095
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
1047
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
1048 // Do not redraw at cursor position.
f452c4aeb837 patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents: 14089
diff changeset
1049 pum_window = NULL;
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1050 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1051
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1052 #endif
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1053
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1054 #if defined(FEAT_BEVAL_TERM) || defined(PROTO)
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1055 static pumitem_T *balloon_array = NULL;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1056 static int balloon_arraysize;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1057
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1058 # define BALLOON_MIN_WIDTH 50
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1059 # define BALLOON_MIN_HEIGHT 10
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1060
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1061 typedef struct {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1062 char_u *start;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1063 int bytelen;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1064 int cells;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1065 int indent;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1066 } balpart_T;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1067
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1068 /*
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1069 * Split a string into parts to display in the balloon.
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1070 * Aimed at output from gdb. Attempts to split at white space, preserve quoted
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1071 * strings and make a struct look good.
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1072 * Resulting array is stored in "array" and returns the size of the array.
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1073 */
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1074 int
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1075 split_message(char_u *mesg, pumitem_T **array)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1076 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1077 garray_T ga;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1078 char_u *p;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1079 balpart_T *item;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1080 int quoted = FALSE;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1081 int height;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1082 int line;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1083 int item_idx;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1084 int indent = 0;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1085 int max_cells = 0;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1086 int max_height = Rows / 2 - 2;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1087 int long_item_count = 0;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1088 int split_long_items = FALSE;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1089
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1090 ga_init2(&ga, sizeof(balpart_T), 20);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1091 p = mesg;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1092
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1093 while (*p != NUL)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1094 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1095 if (ga_grow(&ga, 1) == FAIL)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1096 goto failed;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1097 item = ((balpart_T *)ga.ga_data) + ga.ga_len;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1098 item->start = p;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1099 item->indent = indent;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1100 item->cells = indent * 2;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1101 ++ga.ga_len;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1102 while (*p != NUL)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1103 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1104 if (*p == '"')
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1105 quoted = !quoted;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1106 else if (*p == '\\' && p[1] != NUL)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1107 ++p;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1108 else if (!quoted)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1109 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1110 if ((*p == ',' && p[1] == ' ') || *p == '{' || *p == '}')
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1111 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1112 /* Looks like a good point to break. */
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1113 if (*p == '{')
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1114 ++indent;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1115 else if (*p == '}' && indent > 0)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1116 --indent;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1117 ++item->cells;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1118 p = skipwhite(p + 1);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1119 break;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1120 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1121 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1122 item->cells += ptr2cells(p);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1123 p += MB_PTR2LEN(p);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1124 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1125 item->bytelen = p - item->start;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1126 if (item->cells > max_cells)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1127 max_cells = item->cells;
12940
5045d3076db0 patch 8.0.1346: crash when passing 50 char string to balloon_split()
Christian Brabandt <cb@256bit.org>
parents: 12883
diff changeset
1128 long_item_count += (item->cells - 1) / BALLOON_MIN_WIDTH;
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1129 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1130
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1131 height = 2 + ga.ga_len;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1132
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1133 /* If there are long items and the height is below the limit: split lines */
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1134 if (long_item_count > 0 && height + long_item_count <= max_height)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1135 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1136 split_long_items = TRUE;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1137 height += long_item_count;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1138 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1139
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1140 /* Limit to half the window height, it has to fit above or below the mouse
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1141 * position. */
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1142 if (height > max_height)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1143 height = max_height;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
1144 *array = ALLOC_CLEAR_MULT(pumitem_T, height);
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1145 if (*array == NULL)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1146 goto failed;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1147
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1148 /* Add an empty line above and below, looks better. */
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1149 (*array)->pum_text = vim_strsave((char_u *)"");
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1150 (*array + height - 1)->pum_text = vim_strsave((char_u *)"");
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1151
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1152 for (line = 1, item_idx = 0; line < height - 1; ++item_idx)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1153 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1154 int skip;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1155 int thislen;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1156 int copylen;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1157 int ind;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1158 int cells;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1159
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1160 item = ((balpart_T *)ga.ga_data) + item_idx;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1161 for (skip = 0; skip < item->bytelen; skip += thislen)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1162 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1163 if (split_long_items && item->cells >= BALLOON_MIN_WIDTH)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1164 {
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1165 cells = item->indent * 2;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1166 for (p = item->start + skip; p < item->start + item->bytelen;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1167 p += MB_PTR2LEN(p))
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1168 if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1169 break;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1170 thislen = p - (item->start + skip);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1171 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1172 else
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1173 thislen = item->bytelen;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1174
16429
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1175 // put indent at the start
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1176 p = alloc(thislen + item->indent * 2 + 1);
16429
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1177 if (p == NULL)
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1178 {
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1179 for (line = 0; line <= height - 1; ++line)
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1180 vim_free((*array)[line].pum_text);
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1181 vim_free(*array);
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1182 goto failed;
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1183 }
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1184 for (ind = 0; ind < item->indent * 2; ++ind)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1185 p[ind] = ' ';
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1186
16429
a1229400434a patch 8.1.1219: not checking for NULL return from alloc()
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
1187 // exclude spaces at the end of the string
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1188 for (copylen = thislen; copylen > 0; --copylen)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1189 if (item->start[skip + copylen - 1] != ' ')
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1190 break;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1191
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1192 vim_strncpy(p + ind, item->start + skip, copylen);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1193 (*array)[line].pum_text = p;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1194 item->indent = 0; /* wrapped line has no indent */
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1195 ++line;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1196 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1197 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1198 ga_clear(&ga);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1199 return height;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1200
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1201 failed:
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1202 ga_clear(&ga);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1203 return 0;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1204 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1205
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1206 void
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1207 ui_remove_balloon(void)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1208 {
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1209 if (balloon_array != NULL)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1210 {
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1211 pum_undisplay();
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1212 while (balloon_arraysize > 0)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1213 vim_free(balloon_array[--balloon_arraysize].pum_text);
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13242
diff changeset
1214 VIM_CLEAR(balloon_array);
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1215 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1216 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1217
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1218 /*
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1219 * Terminal version of a balloon, uses the popup menu code.
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1220 */
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1221 void
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1222 ui_post_balloon(char_u *mesg, list_T *list)
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1223 {
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1224 ui_remove_balloon();
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1225
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1226 if (mesg == NULL && list == NULL)
16600
ff3c99bd1038 patch 8.1.1303: not possible to hide a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1227 {
ff3c99bd1038 patch 8.1.1303: not possible to hide a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1228 pum_undisplay();
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1229 return;
16600
ff3c99bd1038 patch 8.1.1303: not possible to hide a balloon
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1230 }
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1231 if (list != NULL)
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1232 {
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1233 listitem_T *li;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1234 int idx;
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1235
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1236 balloon_arraysize = list->lv_len;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
1237 balloon_array = ALLOC_CLEAR_MULT(pumitem_T, list->lv_len);
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1238 if (balloon_array == NULL)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1239 return;
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1240 for (idx = 0, li = list->lv_first; li != NULL; li = li->li_next, ++idx)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1241 {
15211
de63593896b3 patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents: 15087
diff changeset
1242 char_u *text = tv_get_string_chk(&li->li_tv);
12883
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1243
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1244 balloon_array[idx].pum_text = vim_strsave(
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1245 text == NULL ? (char_u *)"" : text);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1246 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1247 }
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1248 else
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1249 balloon_arraysize = split_message(mesg, &balloon_array);
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1250
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1251 if (balloon_arraysize > 0)
058e93aee621 patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents: 12871
diff changeset
1252 {
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1253 pum_array = balloon_array;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1254 pum_size = balloon_arraysize;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1255 pum_compute_size();
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1256 pum_scrollbar = 0;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1257 pum_height = balloon_arraysize;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1258
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1259 pum_position_at_mouse(BALLOON_MIN_WIDTH);
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1260 pum_selected = -1;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1261 pum_first = 0;
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1262 pum_redraw();
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1263 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1264 }
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1265
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1266 /*
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1267 * Called when the mouse moved, may remove any displayed balloon.
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1268 */
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1269 void
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1270 ui_may_remove_balloon(void)
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1271 {
17292
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 17095
diff changeset
1272 // For now: remove the balloon whenever the mouse moves to another screen
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 17095
diff changeset
1273 // cell.
8a095d343c59 patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents: 17095
diff changeset
1274 ui_remove_balloon();
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
1275 }
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1276 #endif
13234
6e972d830e13 patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents: 12940
diff changeset
1277
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1278 #if defined(FEAT_TERM_POPUP_MENU) || defined(PROTO)
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1279 /*
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1280 * Select the pum entry at the mouse position.
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1281 */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1282 static void
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1283 pum_select_mouse_pos(void)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1284 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1285 int idx = mouse_row - pum_row;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1286
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1287 if (idx < 0 || idx >= pum_size)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1288 pum_selected = -1;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1289 else if (*pum_array[idx].pum_text != NUL)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1290 pum_selected = idx;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1291 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1292
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1293 /*
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1294 * Execute the currently selected popup menu item.
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1295 */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1296 static void
13400
c415cdd49ea4 patch 8.0.1574: show cursor in wrong place when using popup menu
Christian Brabandt <cb@256bit.org>
parents: 13392
diff changeset
1297 pum_execute_menu(vimmenu_T *menu, int mode)
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1298 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1299 vimmenu_T *mp;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1300 int idx = 0;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1301 exarg_T ea;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1302
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1303 for (mp = menu->children; mp != NULL; mp = mp->next)
13400
c415cdd49ea4 patch 8.0.1574: show cursor in wrong place when using popup menu
Christian Brabandt <cb@256bit.org>
parents: 13392
diff changeset
1304 if ((mp->modes & mp->enabled & mode) && idx++ == pum_selected)
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1305 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1306 vim_memset(&ea, 0, sizeof(ea));
14952
405309f9dd13 patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents: 14685
diff changeset
1307 execute_menu(&ea, mp, -1);
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1308 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1309 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1310 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1311
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1312 /*
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1313 * Open the terminal version of the popup menu and don't return until it is
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1314 * closed.
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1315 */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1316 void
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1317 pum_show_popupmenu(vimmenu_T *menu)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1318 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1319 vimmenu_T *mp;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1320 int idx = 0;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1321 pumitem_T *array;
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1322 # ifdef FEAT_BEVAL_TERM
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1323 int save_bevalterm = p_bevalterm;
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1324 # endif
13392
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1325 int mode;
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1326
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1327 pum_undisplay();
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1328 pum_size = 0;
13392
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1329 mode = get_menu_mode_flag();
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1330
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1331 for (mp = menu->children; mp != NULL; mp = mp->next)
13392
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1332 if (menu_is_separator(mp->dname)
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1333 || (mp->modes & mp->enabled & mode))
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1334 ++pum_size;
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1335
15375
6012cc6936f7 patch 8.1.0695: internal error when using :popup
Bram Moolenaar <Bram@vim.org>
parents: 15324
diff changeset
1336 // When there are only Terminal mode menus, using "popup Edit" results in
6012cc6936f7 patch 8.1.0695: internal error when using :popup
Bram Moolenaar <Bram@vim.org>
parents: 15324
diff changeset
1337 // pum_size being zero.
6012cc6936f7 patch 8.1.0695: internal error when using :popup
Bram Moolenaar <Bram@vim.org>
parents: 15324
diff changeset
1338 if (pum_size <= 0)
6012cc6936f7 patch 8.1.0695: internal error when using :popup
Bram Moolenaar <Bram@vim.org>
parents: 15324
diff changeset
1339 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15375
diff changeset
1340 emsg(e_menuothermode);
15375
6012cc6936f7 patch 8.1.0695: internal error when using :popup
Bram Moolenaar <Bram@vim.org>
parents: 15324
diff changeset
1341 return;
6012cc6936f7 patch 8.1.0695: internal error when using :popup
Bram Moolenaar <Bram@vim.org>
parents: 15324
diff changeset
1342 }
6012cc6936f7 patch 8.1.0695: internal error when using :popup
Bram Moolenaar <Bram@vim.org>
parents: 15324
diff changeset
1343
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
1344 array = ALLOC_CLEAR_MULT(pumitem_T, pum_size);
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1345 if (array == NULL)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1346 return;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1347
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1348 for (mp = menu->children; mp != NULL; mp = mp->next)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1349 if (menu_is_separator(mp->dname))
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1350 array[idx++].pum_text = (char_u *)"";
13392
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1351 else if (mp->modes & mp->enabled & mode)
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1352 array[idx++].pum_text = mp->dname;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1353
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1354 pum_array = array;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1355 pum_compute_size();
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1356 pum_scrollbar = 0;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1357 pum_height = pum_size;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1358 pum_position_at_mouse(20);
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1359
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1360 pum_selected = -1;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1361 pum_first = 0;
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1362 # ifdef FEAT_BEVAL_TERM
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1363 p_bevalterm = TRUE; /* track mouse movement */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1364 mch_setmouse(TRUE);
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1365 # endif
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1366
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1367 for (;;)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1368 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1369 int c;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1370
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1371 pum_redraw();
13400
c415cdd49ea4 patch 8.0.1574: show cursor in wrong place when using popup menu
Christian Brabandt <cb@256bit.org>
parents: 13392
diff changeset
1372 setcursor_mayforce(TRUE);
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1373 out_flush();
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1374
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1375 c = vgetc();
16845
d4c50bca8dbc patch 8.1.1424: crash when popup menu is deleted while waiting for char
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1376
d4c50bca8dbc patch 8.1.1424: crash when popup menu is deleted while waiting for char
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1377 // Bail out when typing Esc, CTRL-C or some callback closed the popup
d4c50bca8dbc patch 8.1.1424: crash when popup menu is deleted while waiting for char
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1378 // menu.
d4c50bca8dbc patch 8.1.1424: crash when popup menu is deleted while waiting for char
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1379 if (c == ESC || c == Ctrl_C || pum_array == NULL)
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1380 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1381 else if (c == CAR || c == NL)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1382 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1383 /* enter: select current item, if any, and close */
13400
c415cdd49ea4 patch 8.0.1574: show cursor in wrong place when using popup menu
Christian Brabandt <cb@256bit.org>
parents: 13392
diff changeset
1384 pum_execute_menu(menu, mode);
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1385 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1386 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1387 else if (c == 'k' || c == K_UP || c == K_MOUSEUP)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1388 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1389 /* cursor up: select previous item */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1390 while (pum_selected > 0)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1391 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1392 --pum_selected;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1393 if (*array[pum_selected].pum_text != NUL)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1394 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1395 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1396 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1397 else if (c == 'j' || c == K_DOWN || c == K_MOUSEDOWN)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1398 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1399 /* cursor down: select next item */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1400 while (pum_selected < pum_size - 1)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1401 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1402 ++pum_selected;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1403 if (*array[pum_selected].pum_text != NUL)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1404 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1405 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1406 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1407 else if (c == K_RIGHTMOUSE)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1408 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1409 /* Right mouse down: reposition the menu. */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1410 vungetc(c);
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1411 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1412 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1413 else if (c == K_LEFTDRAG || c == K_RIGHTDRAG || c == K_MOUSEMOVE)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1414 {
13427
b85526d90aba patch 8.0.1588: popup menu hangs after typing CTRL-C
Christian Brabandt <cb@256bit.org>
parents: 13400
diff changeset
1415 /* mouse moved: select item in the mouse row */
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1416 pum_select_mouse_pos();
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1417 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1418 else if (c == K_LEFTMOUSE || c == K_LEFTMOUSE_NM || c == K_RIGHTRELEASE)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1419 {
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1420 /* left mouse click: select clicked item, if any, and close;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1421 * right mouse release: select clicked item, close if any */
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1422 pum_select_mouse_pos();
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1423 if (pum_selected >= 0)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1424 {
13400
c415cdd49ea4 patch 8.0.1574: show cursor in wrong place when using popup menu
Christian Brabandt <cb@256bit.org>
parents: 13392
diff changeset
1425 pum_execute_menu(menu, mode);
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1426 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1427 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1428 if (c == K_LEFTMOUSE || c == K_LEFTMOUSE_NM)
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1429 break;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1430 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1431 }
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1432
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1433 vim_free(array);
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1434 pum_undisplay();
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1435 # ifdef FEAT_BEVAL_TERM
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1436 p_bevalterm = save_bevalterm;
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1437 mch_setmouse(TRUE);
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17799
diff changeset
1438 # endif
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1439 }
13392
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1440
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1441 void
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1442 pum_make_popup(char_u *path_name, int use_mouse_pos)
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1443 {
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1444 vimmenu_T *menu;
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1445
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1446 if (!use_mouse_pos)
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1447 {
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1448 /* Hack: set mouse position at the cursor so that the menu pops up
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1449 * around there. */
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1450 mouse_row = curwin->w_winrow + curwin->w_wrow;
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1451 mouse_col = curwin->w_wincol + curwin->w_wcol;
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1452 }
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1453
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1454 menu = gui_find_menu(path_name);
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1455 if (menu != NULL)
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1456 pum_show_popupmenu(menu);
d5347779fb20 patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents: 13369
diff changeset
1457 }
13369
244ff1b6d2ad patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents: 13331
diff changeset
1458 #endif