Mercurial > vim
annotate src/popupmnu.c @ 15049:8fd94c25a939
Added tag v8.1.0535 for changeset 73f59cd01ba74ecc8e82cf02154c04a4473e3d99
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 16 Nov 2018 21:00:06 +0100 |
parents | 405309f9dd13 |
children | 6a74cde86252 |
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 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * popupmnu.c: Popup menu (PUM) | |
12 */ | |
13 #include "vim.h" | |
14 | |
15 #if defined(FEAT_INS_EXPAND) || defined(PROTO) | |
16 | |
17 static pumitem_T *pum_array = NULL; /* items of displayed pum */ | |
18 static int pum_size; /* nr of items in "pum_array" */ | |
19 static int pum_selected; /* index of selected item or -1 */ | |
20 static int pum_first = 0; /* index of top item */ | |
21 | |
22 static int pum_height; /* nr of displayed pum items */ | |
23 static int pum_width; /* width of displayed pum items */ | |
24 static int pum_base_width; /* width of pum items base */ | |
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 | 27 static int pum_scrollbar; /* TRUE when scrollbar present */ |
28 | |
29 static int pum_row; /* top row of pum */ | |
30 static int pum_col; /* left column of pum */ | |
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 |
800 | 39 static int pum_do_redraw = FALSE; /* do redraw anyway */ |
40 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7181
diff
changeset
|
41 static int pum_set_selected(int n, int repeat); |
800 | 42 |
43 #define PUM_DEF_HEIGHT 10 | |
44 #define PUM_DEF_WIDTH 15 | |
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 | 76 /* |
77 * Show the popup menu with items "array[size]". | |
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 | 80 * The menu appears above the screen line "row" or at "row" + "height" - 1. |
81 */ | |
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 | 87 out of range */ |
88 { | |
89 int def_width; | |
90 int max_width; | |
1622 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 172 } |
173 else | |
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 | 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 | 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 | 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) |
14685
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
199 // If there is a preview window at the above avoid drawing over it. |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
200 // Do keep at least 10 entries. |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
201 if (pvwin != NULL && pum_row < above_row && pum_height > 10) |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
202 { |
14685
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
203 if (pum_win_row - above_row < 10) |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
204 { |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
205 pum_row = pum_win_row - 10; |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
206 pum_height = 10; |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
207 } |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
208 else |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
209 { |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
210 pum_row = above_row; |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
211 pum_height = pum_win_row - above_row; |
17a7d9e71ebb
patch 8.1.0355: incorrect adjusting the popup menu for the preview window
Christian Brabandt <cb@256bit.org>
parents:
14095
diff
changeset
|
212 } |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
213 } |
8220
ad9edad64d22
commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
214 #endif |
800 | 215 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
216 pum_array = array; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
217 pum_size = size; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
218 pum_compute_size(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
219 max_width = pum_base_width; |
800 | 220 |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
221 /* Calculate column */ |
1344 | 222 #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
|
223 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
|
224 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
|
225 - 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
|
226 else |
1344 | 227 #endif |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
228 cursor_col = curwin->w_wincol + curwin->w_wcol; |
1344 | 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 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
|
231 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
|
232 { |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
233 pum_scrollbar = 1; |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
234 ++max_width; |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
235 } |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
236 else |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
237 pum_scrollbar = 0; |
800 | 238 |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
239 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
|
240 def_width = max_width; |
800 | 241 |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
242 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
|
243 || cursor_col < Columns - max_width) |
1344 | 244 #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
|
245 && !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
|
246 || (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
|
247 && (cursor_col > p_pw || cursor_col > max_width) |
1344 | 248 #endif |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
249 )) |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
250 { |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
251 /* 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
|
252 pum_col = cursor_col; |
1344 | 253 |
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
|
254 /* start with the maximum space available */ |
1344 | 255 #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
|
256 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
|
257 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
|
258 else |
1344 | 259 #endif |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
260 pum_width = Columns - pum_col - pum_scrollbar; |
1344 | 261 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
262 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
|
263 && 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
|
264 { |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
265 /* 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
|
266 * narrower */ |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 } |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
271 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
|
272 #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
|
273 && !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
|
274 || (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
|
275 || 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
|
276 #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
|
277 )) |
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 { |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
279 /* 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
|
280 #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
|
281 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
|
282 && 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
|
283 { |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 } |
13296
67345bc7fe31
patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
288 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
|
289 #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
|
290 { |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
291 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
|
292 && 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
|
293 { |
13331
1ba4f926247c
patch 8.0.1540: popup menu positioning fails with longer string
Christian Brabandt <cb@256bit.org>
parents:
13328
diff
changeset
|
294 /* 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
|
295 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
|
296 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
|
297 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
|
298 } |
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
|
299 } |
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 |
6e972d830e13
patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents:
12940
diff
changeset
|
301 #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
|
302 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
|
303 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
|
304 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
|
305 #endif |
13296
67345bc7fe31
patch 8.0.1522: popup menu is positioned in the wrong place
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
306 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
|
307 |
13242
5b0faf628a55
patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents:
13234
diff
changeset
|
308 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
|
309 { |
13242
5b0faf628a55
patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents:
13234
diff
changeset
|
310 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
|
311 #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
|
312 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
|
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 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
|
315 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
|
316 } |
6e972d830e13
patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents:
12940
diff
changeset
|
317 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
|
318 #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
|
319 { |
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 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
|
321 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
|
322 } |
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 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
|
325 + 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
|
326 && 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
|
327 { |
6e972d830e13
patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents:
12940
diff
changeset
|
328 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
|
329 + 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
|
330 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
|
331 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
|
332 } |
6e972d830e13
patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents:
12940
diff
changeset
|
333 } |
6e972d830e13
patch 8.0.1491: the minimum width of the popup menu is hard coded
Christian Brabandt <cb@256bit.org>
parents:
12940
diff
changeset
|
334 |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
335 } |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
336 else if (Columns < def_width) |
800 | 337 { |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
338 /* not enough room, will use what we have */ |
1344 | 339 #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
|
340 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
|
341 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
|
342 else |
1344 | 343 #endif |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
344 pum_col = 0; |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
345 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
|
346 } |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
347 else |
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
348 { |
13242
5b0faf628a55
patch 8.0.1495: having 'pumwidth' default to zero has no merit
Christian Brabandt <cb@256bit.org>
parents:
13234
diff
changeset
|
349 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
|
350 max_width = p_pw; /* truncate */ |
1344 | 351 #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
|
352 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
|
353 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
|
354 else |
1344 | 355 #endif |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
356 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
|
357 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
|
358 } |
800 | 359 |
12566
33a900199c25
patch 8.0.1161: popup menu drawing problem when resizing terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
360 /* 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
|
361 * 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
|
362 * 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
|
363 } while (pum_set_selected(selected, redo_count) && ++redo_count <= 2); |
800 | 364 } |
365 | |
366 /* | |
367 * Redraw the popup menu, using "pum_first" and "pum_selected". | |
368 */ | |
369 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
370 pum_redraw(void) |
800 | 371 { |
372 int row = pum_row; | |
373 int col; | |
374 int attr_norm = highlight_attr[HLF_PNI]; | |
375 int attr_select = highlight_attr[HLF_PSI]; | |
376 int attr_scroll = highlight_attr[HLF_PSB]; | |
377 int attr_thumb = highlight_attr[HLF_PST]; | |
378 int attr; | |
379 int i; | |
380 int idx; | |
381 char_u *s; | |
382 char_u *p = NULL; | |
383 int totwidth, width, w; | |
384 int thumb_pos = 0; | |
385 int thumb_heigth = 1; | |
386 int round; | |
387 int n; | |
388 | |
5444 | 389 /* Never display more than we have */ |
390 if (pum_first > pum_size - pum_height) | |
391 pum_first = pum_size - pum_height; | |
392 | |
800 | 393 if (pum_scrollbar) |
394 { | |
395 thumb_heigth = pum_height * pum_height / pum_size; | |
396 if (thumb_heigth == 0) | |
397 thumb_heigth = 1; | |
398 thumb_pos = (pum_first * (pum_height - thumb_heigth) | |
399 + (pum_size - pum_height) / 2) | |
400 / (pum_size - pum_height); | |
401 } | |
402 | |
403 for (i = 0; i < pum_height; ++i) | |
404 { | |
405 idx = i + pum_first; | |
406 attr = (idx == pum_selected) ? attr_select : attr_norm; | |
407 | |
408 /* prepend a space if there is room */ | |
1344 | 409 #ifdef FEAT_RIGHTLEFT |
410 if (curwin->w_p_rl) | |
411 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
412 if (pum_col < curwin->w_wincol + curwin->w_width - 1) |
1344 | 413 screen_putchar(' ', row, pum_col + 1, attr); |
414 } | |
415 else | |
416 #endif | |
417 if (pum_col > 0) | |
418 screen_putchar(' ', row, pum_col - 1, attr); | |
800 | 419 |
420 /* Display each entry, use two spaces for a Tab. | |
421 * Do this 3 times: For the main text, kind and extra info */ | |
422 col = pum_col; | |
423 totwidth = 0; | |
424 for (round = 1; round <= 3; ++round) | |
425 { | |
426 width = 0; | |
427 s = NULL; | |
428 switch (round) | |
429 { | |
430 case 1: p = pum_array[idx].pum_text; break; | |
431 case 2: p = pum_array[idx].pum_kind; break; | |
432 case 3: p = pum_array[idx].pum_extra; break; | |
433 } | |
434 if (p != NULL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
435 for ( ; ; MB_PTR_ADV(p)) |
800 | 436 { |
437 if (s == NULL) | |
438 s = p; | |
439 w = ptr2cells(p); | |
440 if (*p == NUL || *p == TAB || totwidth + w > pum_width) | |
441 { | |
1097 | 442 /* Display the text that fits or comes before a Tab. |
443 * First convert it to printable characters. */ | |
1344 | 444 char_u *st; |
445 int saved = *p; | |
1097 | 446 |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
447 if (saved != NUL) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
448 *p = NUL; |
1097 | 449 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
|
450 if (saved != NUL) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
451 *p = saved; |
1344 | 452 #ifdef FEAT_RIGHTLEFT |
453 if (curwin->w_p_rl) | |
1097 | 454 { |
1344 | 455 if (st != NULL) |
456 { | |
457 char_u *rt = reverse_text(st); | |
458 | |
459 if (rt != NULL) | |
460 { | |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
461 char_u *rt_start = rt; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
462 int size; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
463 |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
464 size = vim_strsize(rt); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
465 if (size > pum_width) |
1344 | 466 { |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
467 do |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
468 { |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
469 size -= has_mbyte |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
470 ? (*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
|
471 MB_PTR_ADV(rt); |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
472 } while (size > pum_width); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
473 |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
474 if (size < pum_width) |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
475 { |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
476 /* Most left character requires |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
477 * 2-cells but only 1 cell is |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
478 * available on screen. Put a |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
479 * '<' on the left of the pum |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
480 * item */ |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
481 *(--rt) = '<'; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
482 size++; |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
483 } |
1344 | 484 } |
2056
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
485 screen_puts_len(rt, (int)STRLEN(rt), |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
486 row, col - size + 1, attr); |
e9e3355861ba
updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents:
1743
diff
changeset
|
487 vim_free(rt_start); |
1344 | 488 } |
489 vim_free(st); | |
490 } | |
491 col -= width; | |
492 } | |
493 else | |
494 #endif | |
495 { | |
496 if (st != NULL) | |
497 { | |
498 screen_puts_len(st, (int)STRLEN(st), row, col, | |
1097 | 499 attr); |
1344 | 500 vim_free(st); |
501 } | |
502 col += width; | |
1097 | 503 } |
800 | 504 |
505 if (*p != TAB) | |
506 break; | |
507 | |
508 /* Display two spaces for a Tab. */ | |
1344 | 509 #ifdef FEAT_RIGHTLEFT |
510 if (curwin->w_p_rl) | |
511 { | |
512 screen_puts_len((char_u *)" ", 2, row, col - 1, | |
513 attr); | |
514 col -= 2; | |
515 } | |
516 else | |
517 #endif | |
518 { | |
519 screen_puts_len((char_u *)" ", 2, row, col, attr); | |
520 col += 2; | |
521 } | |
800 | 522 totwidth += 2; |
523 s = NULL; /* start text at next char */ | |
524 width = 0; | |
525 } | |
526 else | |
527 width += w; | |
528 } | |
529 | |
530 if (round > 1) | |
531 n = pum_kind_width + 1; | |
532 else | |
533 n = 1; | |
534 | |
535 /* Stop when there is nothing more to display. */ | |
536 if (round == 3 | |
537 || (round == 2 && pum_array[idx].pum_extra == NULL) | |
538 || (round == 1 && pum_array[idx].pum_kind == NULL | |
539 && pum_array[idx].pum_extra == NULL) | |
540 || pum_base_width + n >= pum_width) | |
541 break; | |
1344 | 542 #ifdef FEAT_RIGHTLEFT |
543 if (curwin->w_p_rl) | |
544 { | |
545 screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, | |
546 col + 1, ' ', ' ', attr); | |
547 col = pum_col - pum_base_width - n + 1; | |
548 } | |
549 else | |
550 #endif | |
551 { | |
552 screen_fill(row, row + 1, col, pum_col + pum_base_width + n, | |
800 | 553 ' ', ' ', attr); |
1344 | 554 col = pum_col + pum_base_width + n; |
555 } | |
800 | 556 totwidth = pum_base_width + n; |
557 } | |
558 | |
1344 | 559 #ifdef FEAT_RIGHTLEFT |
560 if (curwin->w_p_rl) | |
561 screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', | |
562 ' ', attr); | |
563 else | |
564 #endif | |
565 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', | |
566 attr); | |
800 | 567 if (pum_scrollbar > 0) |
1344 | 568 { |
569 #ifdef FEAT_RIGHTLEFT | |
570 if (curwin->w_p_rl) | |
571 screen_putchar(' ', row, pum_col - pum_width, | |
572 i >= thumb_pos && i < thumb_pos + thumb_heigth | |
800 | 573 ? attr_thumb : attr_scroll); |
1344 | 574 else |
575 #endif | |
576 screen_putchar(' ', row, pum_col + pum_width, | |
577 i >= thumb_pos && i < thumb_pos + thumb_heigth | |
578 ? attr_thumb : attr_scroll); | |
579 } | |
800 | 580 |
581 ++row; | |
582 } | |
583 } | |
584 | |
585 /* | |
586 * Set the index of the currently selected item. The menu will scroll when | |
587 * necessary. When "n" is out of range don't scroll. | |
838 | 588 * This may be repeated when the preview window is used: |
589 * "repeat" == 0: open preview window normally | |
590 * "repeat" == 1: open preview window but don't set the size | |
591 * "repeat" == 2: don't open preview window | |
800 | 592 * Returns TRUE when the window was resized and the location of the popup menu |
593 * must be recomputed. | |
594 */ | |
595 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
596 pum_set_selected(int n, int repeat) |
800 | 597 { |
598 int resized = FALSE; | |
599 int context = pum_height / 2; | |
600 | |
601 pum_selected = n; | |
602 | |
603 if (pum_selected >= 0 && pum_selected < pum_size) | |
604 { | |
605 if (pum_first > pum_selected - 4) | |
606 { | |
607 /* scroll down; when we did a jump it's probably a PageUp then | |
608 * scroll a whole page */ | |
609 if (pum_first > pum_selected - 2) | |
610 { | |
611 pum_first -= pum_height - 2; | |
612 if (pum_first < 0) | |
613 pum_first = 0; | |
614 else if (pum_first > pum_selected) | |
615 pum_first = pum_selected; | |
616 } | |
617 else | |
618 pum_first = pum_selected; | |
619 } | |
620 else if (pum_first < pum_selected - pum_height + 5) | |
621 { | |
622 /* scroll up; when we did a jump it's probably a PageDown then | |
623 * scroll a whole page */ | |
624 if (pum_first < pum_selected - pum_height + 1 + 2) | |
625 { | |
626 pum_first += pum_height - 2; | |
627 if (pum_first < pum_selected - pum_height + 1) | |
628 pum_first = pum_selected - pum_height + 1; | |
629 } | |
630 else | |
631 pum_first = pum_selected - pum_height + 1; | |
632 } | |
633 | |
634 /* Give a few lines of context when possible. */ | |
635 if (context > 3) | |
636 context = 3; | |
637 if (pum_height > 2) | |
638 { | |
639 if (pum_first > pum_selected - context) | |
640 { | |
641 /* scroll down */ | |
642 pum_first = pum_selected - context; | |
643 if (pum_first < 0) | |
644 pum_first = 0; | |
645 } | |
646 else if (pum_first < pum_selected + context - pum_height + 1) | |
647 { | |
648 /* scroll up */ | |
649 pum_first = pum_selected + context - pum_height + 1; | |
650 } | |
651 } | |
652 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
653 #if defined(FEAT_QUICKFIX) |
816 | 654 /* |
655 * Show extra info in the preview window if there is something and | |
656 * 'completeopt' contains "preview". | |
838 | 657 * Skip this when tried twice already. |
658 * Skip this also when there is not much room. | |
816 | 659 * NOTE: Be very careful not to sync undo! |
660 */ | |
800 | 661 if (pum_array[pum_selected].pum_info != NULL |
838 | 662 && Rows > 10 |
663 && repeat <= 1 | |
664 && vim_strchr(p_cot, 'p') != NULL) | |
800 | 665 { |
666 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
|
667 tabpage_T *curtab_save = curtab; |
800 | 668 int res = OK; |
669 | |
2622 | 670 /* Open a preview window. 3 lines by default. Prefer |
671 * 'previewheight' if set and smaller. */ | |
800 | 672 g_do_tagpreview = 3; |
2622 | 673 if (p_pvh > 0 && p_pvh < g_do_tagpreview) |
674 g_do_tagpreview = p_pvh; | |
6043 | 675 ++RedrawingDisabled; |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
676 /* Prevent undo sync here, if an autocommand syncs undo weird |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
677 * things can happen to the undo tree. */ |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
678 ++no_u_sync; |
816 | 679 resized = prepare_tagpreview(FALSE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
680 --no_u_sync; |
6043 | 681 --RedrawingDisabled; |
800 | 682 g_do_tagpreview = 0; |
683 | |
684 if (curwin->w_p_pvw) | |
685 { | |
10302
210af8588e8a
commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
686 if (!resized |
210af8588e8a
commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
687 && curbuf->b_nwindows == 1 |
210af8588e8a
commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
688 && curbuf->b_fname == NULL |
800 | 689 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' |
690 && curbuf->b_p_bh[0] == 'w') | |
691 { | |
692 /* 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
|
693 while (!BUFEMPTY()) |
800 | 694 ml_delete((linenr_T)1, FALSE); |
695 } | |
825 | 696 else |
800 | 697 { |
825 | 698 /* Don't want to sync undo in the current buffer. */ |
699 ++no_u_sync; | |
1743 | 700 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); |
825 | 701 --no_u_sync; |
702 if (res == OK) | |
703 { | |
704 /* Edit a new, empty buffer. Set options for a "wipeout" | |
705 * buffer. */ | |
706 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
707 set_option_value((char_u *)"bt", 0L, | |
708 (char_u *)"nofile", OPT_LOCAL); | |
709 set_option_value((char_u *)"bh", 0L, | |
710 (char_u *)"wipe", OPT_LOCAL); | |
711 set_option_value((char_u *)"diff", 0L, | |
1302 | 712 NULL, OPT_LOCAL); |
825 | 713 } |
800 | 714 } |
715 if (res == OK) | |
716 { | |
717 char_u *p, *e; | |
718 linenr_T lnum = 0; | |
719 | |
720 for (p = pum_array[pum_selected].pum_info; *p != NUL; ) | |
721 { | |
722 e = vim_strchr(p, '\n'); | |
723 if (e == NULL) | |
724 { | |
725 ml_append(lnum++, p, 0, FALSE); | |
726 break; | |
727 } | |
728 else | |
729 { | |
730 *e = NUL; | |
835 | 731 ml_append(lnum++, p, (int)(e - p + 1), FALSE); |
800 | 732 *e = '\n'; |
733 p = e + 1; | |
734 } | |
735 } | |
736 | |
737 /* Increase the height of the preview window to show the | |
738 * text, but no more than 'previewheight' lines. */ | |
838 | 739 if (repeat == 0) |
800 | 740 { |
838 | 741 if (lnum > p_pvh) |
742 lnum = p_pvh; | |
743 if (curwin->w_height < lnum) | |
744 { | |
745 win_setheight((int)lnum); | |
746 resized = TRUE; | |
747 } | |
800 | 748 } |
749 | |
750 curbuf->b_changed = 0; | |
751 curbuf->b_p_ma = FALSE; | |
2113
85ad19790706
updated for version 7.2.396
Bram Moolenaar <bram@zimbu.org>
parents:
2056
diff
changeset
|
752 curwin->w_cursor.lnum = 1; |
800 | 753 curwin->w_cursor.col = 0; |
754 | |
12690
fad36581f788
patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents:
12566
diff
changeset
|
755 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
|
756 || (curtab != curtab_save |
fad36581f788
patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents:
12566
diff
changeset
|
757 && valid_tabpage(curtab_save))) |
800 | 758 { |
12690
fad36581f788
patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents:
12566
diff
changeset
|
759 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
|
760 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
|
761 |
6089 | 762 /* When the first completion is done and the preview |
763 * window is not resized, skip the preview window's | |
764 * status line redrawing. */ | |
765 if (ins_compl_active() && !resized) | |
766 curwin->w_redr_status = FALSE; | |
767 | |
800 | 768 /* Return cursor to where we were */ |
769 validate_cursor(); | |
770 redraw_later(SOME_VALID); | |
771 | |
772 /* When the preview window was resized we need to | |
773 * update the view on the buffer. Only go back to | |
774 * the window when needed, otherwise it will always be | |
775 * redraw. */ | |
776 if (resized) | |
777 { | |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
778 ++no_u_sync; |
800 | 779 win_enter(curwin_save, TRUE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
780 --no_u_sync; |
800 | 781 update_topline(); |
782 } | |
783 | |
784 /* Update the screen before drawing the popup menu. | |
785 * Enable updating the status lines. */ | |
786 pum_do_redraw = TRUE; | |
787 update_screen(0); | |
788 pum_do_redraw = FALSE; | |
789 | |
816 | 790 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
|
791 { |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
792 ++no_u_sync; |
800 | 793 win_enter(curwin_save, TRUE); |
7181
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
794 --no_u_sync; |
ce8b286e89ef
commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents:
6089
diff
changeset
|
795 } |
800 | 796 |
797 /* May need to update the screen again when there are | |
798 * autocommands involved. */ | |
799 pum_do_redraw = TRUE; | |
800 update_screen(0); | |
801 pum_do_redraw = FALSE; | |
802 } | |
803 } | |
804 } | |
805 } | |
806 #endif | |
807 } | |
808 | |
809 if (!resized) | |
810 pum_redraw(); | |
811 | |
812 return resized; | |
813 } | |
814 | |
815 /* | |
816 * Undisplay the popup menu (later). | |
817 */ | |
818 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
819 pum_undisplay(void) |
800 | 820 { |
821 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
|
822 redraw_all_later(NOT_VALID); |
940 | 823 redraw_tabline = TRUE; |
800 | 824 status_redraw_all(); |
825 } | |
826 | |
827 /* | |
828 * Clear the popup menu. Currently only resets the offset to the first | |
829 * displayed item. | |
830 */ | |
831 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
832 pum_clear(void) |
800 | 833 { |
834 pum_first = 0; | |
835 } | |
836 | |
837 /* | |
838 * Return TRUE if the popup menu is displayed. | |
839 * Overruled when "pum_do_redraw" is set, used to redraw the status lines. | |
840 */ | |
841 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
842 pum_visible(void) |
800 | 843 { |
844 return !pum_do_redraw && pum_array != NULL; | |
845 } | |
846 | |
847 /* | |
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
|
848 * 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
|
849 */ |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
850 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
|
851 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
|
852 { |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
853 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
|
854 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
|
855 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
|
856 |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
857 if (!pum_visible()) |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
858 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
|
859 |
14095
f452c4aeb837
patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents:
14089
diff
changeset
|
860 if (pum_window != curwin |
f452c4aeb837
patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents:
14089
diff
changeset
|
861 || (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
|
862 && 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
|
863 && 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
|
864 && 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
|
865 { |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
866 // 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
|
867 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
|
868 } |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
869 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
|
870 { |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
871 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
|
872 |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
873 // 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
|
874 // 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
|
875 // 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
|
876 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
|
877 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
|
878 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
|
879 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
|
880 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
|
881 } |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
882 } |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
883 |
ae53a9274f50
patch 8.1.0062: popup menu broken if a callback changes the window layout
Christian Brabandt <cb@256bit.org>
parents:
13944
diff
changeset
|
884 /* |
800 | 885 * Return the height of the popup menu, the number of entries visible. |
886 * Only valid when pum_visible() returns TRUE! | |
887 */ | |
888 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
889 pum_get_height(void) |
800 | 890 { |
891 return pum_height; | |
892 } | |
893 | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
894 # if defined(FEAT_BEVAL_TERM) || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
895 static void |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
896 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
|
897 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
898 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
|
899 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
900 /* 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
|
901 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
|
902 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
|
903 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
|
904 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
905 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
906 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
907 /* 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
|
908 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
|
909 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
|
910 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
911 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
|
912 pum_row = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
913 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
914 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
915 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
|
916 || 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
|
917 /* 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
|
918 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
|
919 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
920 /* 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
|
921 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
|
922 ? 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
|
923 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
924 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
|
925 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
|
926 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
|
927 |
f452c4aeb837
patch 8.1.0065: balloon displayed at the wrong position
Christian Brabandt <cb@256bit.org>
parents:
14089
diff
changeset
|
928 // 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
|
929 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
|
930 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
931 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
932 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
933 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
934 # 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
|
935 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
|
936 static int balloon_arraysize; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
937 static int balloon_mouse_row = 0; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
938 static int balloon_mouse_col = 0; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
939 |
12883
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
940 #define BALLOON_MIN_WIDTH 50 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
941 #define BALLOON_MIN_HEIGHT 10 |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
942 |
12883
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
943 typedef struct { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
944 char_u *start; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
945 int bytelen; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
946 int cells; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
947 int indent; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
948 } balpart_T; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
949 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
950 /* |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
951 * 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
|
952 * 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
|
953 * 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
|
954 * 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
|
955 */ |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
956 int |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
957 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
|
958 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
959 garray_T ga; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
960 char_u *p; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
961 balpart_T *item; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
962 int quoted = FALSE; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
963 int height; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
964 int line; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
965 int item_idx; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
966 int indent = 0; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
967 int max_cells = 0; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
968 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
|
969 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
|
970 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
|
971 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
972 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
|
973 p = mesg; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
974 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
975 while (*p != NUL) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
976 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
977 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
|
978 goto failed; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
979 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
|
980 item->start = p; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
981 item->indent = indent; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
982 item->cells = indent * 2; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
983 ++ga.ga_len; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
984 while (*p != NUL) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
985 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
986 if (*p == '"') |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
987 quoted = !quoted; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
988 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
|
989 ++p; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
990 else if (!quoted) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
991 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
992 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
|
993 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
994 /* 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
|
995 if (*p == '{') |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
996 ++indent; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
997 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
|
998 --indent; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
999 ++item->cells; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1000 p = skipwhite(p + 1); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1001 break; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1002 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1003 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1004 item->cells += ptr2cells(p); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1005 p += MB_PTR2LEN(p); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1006 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1012 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1013 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
|
1014 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1015 /* 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
|
1016 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
|
1017 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1018 split_long_items = TRUE; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1019 height += long_item_count; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1020 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1021 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1022 /* 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
|
1023 * position. */ |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1024 if (height > max_height) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1025 height = max_height; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1026 *array = (pumitem_T *)alloc_clear((unsigned)sizeof(pumitem_T) * height); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1027 if (*array == NULL) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1028 goto failed; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1029 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1030 /* 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
|
1031 (*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
|
1032 (*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
|
1033 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1034 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
|
1035 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1036 int skip; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1037 int thislen; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1038 int copylen; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1039 int ind; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1040 int cells; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1041 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1042 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
|
1043 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
|
1044 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1045 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
|
1046 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1047 cells = item->indent * 2; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1048 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
|
1049 p += MB_PTR2LEN(p)) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1050 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
|
1051 break; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1052 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
|
1053 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1054 else |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1055 thislen = item->bytelen; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1056 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1057 /* put indent at the start */ |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1058 p = alloc(thislen + item->indent * 2 + 1); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1059 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
|
1060 p[ind] = ' '; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1061 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1062 /* exclude spaces at the end of the string */ |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1063 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
|
1064 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
|
1065 break; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1066 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1067 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
|
1068 (*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
|
1069 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
|
1070 ++line; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1071 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1072 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1073 ga_clear(&ga); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1074 return height; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1075 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1076 failed: |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1077 ga_clear(&ga); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1078 return 0; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1079 } |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1080 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1081 void |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1082 ui_remove_balloon(void) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1083 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1084 if (balloon_array != NULL) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1085 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1086 pum_undisplay(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1087 while (balloon_arraysize > 0) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1088 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
|
1089 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
|
1090 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1091 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1092 |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1093 /* |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1094 * 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
|
1095 */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1096 void |
12883
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1097 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
|
1098 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1099 ui_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1100 |
12883
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1101 if (mesg == NULL && list == NULL) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1102 return; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1103 if (list != NULL) |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1104 { |
12883
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1105 listitem_T *li; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1106 int idx; |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1107 |
12883
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1108 balloon_arraysize = list->lv_len; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1109 balloon_array = (pumitem_T *)alloc_clear( |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1110 (unsigned)sizeof(pumitem_T) * list->lv_len); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1111 if (balloon_array == NULL) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1112 return; |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1113 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
|
1114 { |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1115 char_u *text = get_tv_string_chk(&li->li_tv); |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1116 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1117 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
|
1118 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
|
1119 } |
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 else |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1122 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
|
1123 |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1124 if (balloon_arraysize > 0) |
058e93aee621
patch 8.0.1318: terminal balloon only shows one line
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
1125 { |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1126 pum_array = balloon_array; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1127 pum_size = balloon_arraysize; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1128 pum_compute_size(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1129 pum_scrollbar = 0; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1130 pum_height = balloon_arraysize; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1131 |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1132 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
|
1133 pum_selected = -1; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1134 pum_first = 0; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1135 pum_redraw(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1136 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1137 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1138 |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1139 /* |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1140 * 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
|
1141 */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1142 void |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1143 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
|
1144 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1145 if (mouse_row != balloon_mouse_row || mouse_col != balloon_mouse_col) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1146 ui_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1147 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12690
diff
changeset
|
1148 # 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
|
1149 |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1150 # if defined(FEAT_TERM_POPUP_MENU) || defined(PROTO) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1151 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1152 * 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
|
1153 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1154 static void |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1155 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
|
1156 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1157 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
|
1158 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1159 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
|
1160 pum_selected = -1; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1161 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
|
1162 pum_selected = idx; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1163 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1164 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1165 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1166 * 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
|
1167 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1168 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
|
1169 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
|
1170 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1171 vimmenu_T *mp; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1172 int idx = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1173 exarg_T ea; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1174 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1175 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
|
1176 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
|
1177 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1178 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
|
1179 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
|
1180 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1181 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1182 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1183 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1184 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1185 * 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
|
1186 * closed. |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1187 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1188 void |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1189 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
|
1190 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1191 vimmenu_T *mp; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1192 int idx = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1193 pumitem_T *array; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1194 #ifdef FEAT_BEVAL_TERM |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1195 int save_bevalterm = p_bevalterm; |
800 | 1196 #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
|
1197 int mode; |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1198 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1199 pum_undisplay(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1200 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
|
1201 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
|
1202 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1203 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
|
1204 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
|
1205 || (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
|
1206 ++pum_size; |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1207 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1208 array = (pumitem_T *)alloc_clear((unsigned)sizeof(pumitem_T) * pum_size); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1209 if (array == NULL) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1210 return; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1211 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1212 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
|
1213 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
|
1214 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
|
1215 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
|
1216 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
|
1217 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1218 pum_array = array; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1219 pum_compute_size(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1220 pum_scrollbar = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1221 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
|
1222 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
|
1223 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1224 pum_selected = -1; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1225 pum_first = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1226 # ifdef FEAT_BEVAL_TERM |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1227 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
|
1228 mch_setmouse(TRUE); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1229 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1230 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1231 for (;;) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1232 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1233 int c; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1234 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1235 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
|
1236 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
|
1237 out_flush(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1238 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1239 c = vgetc(); |
13427
b85526d90aba
patch 8.0.1588: popup menu hangs after typing CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
13400
diff
changeset
|
1240 if (c == ESC || c == Ctrl_C) |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1241 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1242 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
|
1243 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1244 /* 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
|
1245 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
|
1246 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1247 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1248 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
|
1249 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1250 /* 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
|
1251 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
|
1252 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1253 --pum_selected; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1254 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
|
1255 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1256 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1257 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1258 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
|
1259 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1260 /* 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
|
1261 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
|
1262 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1263 ++pum_selected; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1264 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
|
1265 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1266 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1267 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1268 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
|
1269 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1270 /* 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
|
1271 vungetc(c); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1272 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1273 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1274 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
|
1275 { |
13427
b85526d90aba
patch 8.0.1588: popup menu hangs after typing CTRL-C
Christian Brabandt <cb@256bit.org>
parents:
13400
diff
changeset
|
1276 /* 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
|
1277 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
|
1278 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1279 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
|
1280 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1281 /* 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
|
1282 * 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
|
1283 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
|
1284 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
|
1285 { |
13400
c415cdd49ea4
patch 8.0.1574: show cursor in wrong place when using popup menu
Christian Brabandt <cb@256bit.org>
parents:
13392
diff
changeset
|
1286 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
|
1287 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1288 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1289 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
|
1290 break; |
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 vim_free(array); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1295 pum_undisplay(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1296 # ifdef FEAT_BEVAL_TERM |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1297 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
|
1298 mch_setmouse(TRUE); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1299 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1300 } |
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
|
1301 |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1302 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
|
1303 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
|
1304 { |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1305 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
|
1306 |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1307 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
|
1308 { |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1309 /* 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
|
1310 * 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
|
1311 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
|
1312 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
|
1313 } |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1314 |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1315 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
|
1316 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
|
1317 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
|
1318 } |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1319 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1320 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13331
diff
changeset
|
1321 #endif |