annotate src/popupmenu.c @ 743:afac7b58ed46

updated for version 7.0222
author vimboss
date Sun, 12 Mar 2006 22:05:10 +0000
parents 44348703ab1b
children ac005a544e24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
2 *
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
4 *
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
8 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
9
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
10 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
11 * popupmenu.c: Popup menu (PUM)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
12 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
13 #include "vim.h"
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
14
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
15 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
16
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
17 static pumitem_T *pum_array = NULL; /* items of displayed pum */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
18 static int pum_size; /* nr of items in "pum_array" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
19 static int pum_selected; /* index of selected item or -1 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
20 static int pum_first = 0; /* index of top item */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
21
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
22 static int pum_height; /* nr of displayed pum items */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
23 static int pum_width; /* width of displayed pum items */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
24 static int pum_base_width; /* width of pum items base */
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
25 static int pum_kind_width; /* width of pum items kind column */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
26 static int pum_scrollbar; /* TRUE when scrollbar present */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
27
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
28 static int pum_row; /* top row of pum */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
29 static int pum_col; /* left column of pum */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
30
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
31 static int pum_do_redraw = FALSE; /* do redraw anyway */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
32
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
33 static int pum_set_selected __ARGS((int n));
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
34
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
35 #define PUM_DEF_HEIGHT 10
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
36 #define PUM_DEF_WIDTH 15
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
37
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
38 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
39 * Show the popup menu with items "array[size]".
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
40 * "array" must remain valid until pum_undisplay() is called!
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
41 * When possible the leftmost character is aligned with screen column "col".
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
42 * The menu appears above the screen line "row" or at "row" + "height" - 1.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
43 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
44 void
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
45 pum_display(array, size, selected)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
46 pumitem_T *array;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
47 int size;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
48 int selected; /* index of initially selected item, none if
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
49 out of range */
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
50 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
51 int w;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
52 int def_width;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
53 int max_width;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
54 int kind_width;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
55 int extra_width;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
56 int i;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
57 int top_clear;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
58 int row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
59 int height;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
60 int col;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
61
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
62 redo:
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
63 def_width = PUM_DEF_WIDTH;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
64 max_width = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
65 kind_width = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
66 extra_width = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
67
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
68 validate_cursor_col();
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
69 row = curwin->w_cline_row + W_WINROW(curwin);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
70 height = curwin->w_cline_height;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
71 col = curwin->w_wcol + W_WINCOL(curwin) - curwin->w_leftcol;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
72
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
73 if (firstwin->w_p_pvw)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
74 top_clear = firstwin->w_height;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
75 else
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
76 top_clear = 0;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
77
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
78 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
79 * Figure out the size and position of the pum.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
80 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
81 if (size < PUM_DEF_HEIGHT)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
82 pum_height = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
83 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
84 pum_height = PUM_DEF_HEIGHT;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
85
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
86 /* Put the pum below "row" if possible. If there are few lines decide on
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
87 * where there is more room. */
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
88 if (row >= cmdline_row - top_clear - pum_height
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
89 && row > (cmdline_row - top_clear - height) / 2)
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
90 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
91 /* pum above "row" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
92 if (row >= size)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
93 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
94 pum_row = row - size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
95 pum_height = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
96 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
97 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
98 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
99 pum_row = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
100 pum_height = row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
101 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
102 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
103 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
104 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
105 /* pum below "row" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
106 pum_row = row + height;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
107 if (size > cmdline_row - pum_row)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
108 pum_height = cmdline_row - pum_row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
109 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
110 pum_height = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
111 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
112
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
113 /* don't display when we only have room for one line */
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 642
diff changeset
114 if (pum_height < 1 || (pum_height == 1 && size > 1))
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
115 return;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
116
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
117 /* If there is a preview window at the top avoid drawing over it. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
118 if (firstwin->w_p_pvw
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
119 && pum_row < firstwin->w_height
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
120 && pum_height > firstwin->w_height + 4)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
121 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
122 pum_row += firstwin->w_height;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
123 pum_height -= firstwin->w_height;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
124 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
125
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
126 /* Compute the width of the widest match and the widest extra. */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
127 for (i = 0; i < size; ++i)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
128 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
129 w = vim_strsize(array[i].pum_text);
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
130 if (max_width < w)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
131 max_width = w;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
132 if (array[i].pum_kind != NULL)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
133 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
134 w = vim_strsize(array[i].pum_kind) + 1;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
135 if (kind_width < w)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
136 kind_width = w;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
137 }
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
138 if (array[i].pum_extra != NULL)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
139 {
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
140 w = vim_strsize(array[i].pum_extra + 1);
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
141 if (extra_width < w)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
142 extra_width = w;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
143 }
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
144 }
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
145 pum_base_width = max_width;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
146 pum_kind_width = kind_width;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
147
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
148 /* if there are more items than room we need a scrollbar */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
149 if (pum_height < size)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
150 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
151 pum_scrollbar = 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
152 ++max_width;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
153 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
154 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
155 pum_scrollbar = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
156
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
157 if (def_width < max_width)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
158 def_width = max_width;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
159
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
160 if (col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
161 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
162 /* align pum column with "col" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
163 pum_col = col;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
164 pum_width = Columns - pum_col - pum_scrollbar;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
165 if (pum_width > max_width + kind_width + extra_width + 1
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
166 && pum_width > PUM_DEF_WIDTH)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
167 {
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
168 pum_width = max_width + kind_width + extra_width + 1;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
169 if (pum_width < PUM_DEF_WIDTH)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
170 pum_width = PUM_DEF_WIDTH;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
171 }
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
172 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
173 else if (Columns < def_width)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
174 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
175 /* not enough room, will use what we have */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
176 pum_col = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
177 pum_width = Columns - 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
178 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
179 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
180 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
181 if (max_width > PUM_DEF_WIDTH)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
182 max_width = PUM_DEF_WIDTH; /* truncate */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
183 pum_col = Columns - max_width;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
184 pum_width = max_width - pum_scrollbar;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
185 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
186
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
187 pum_array = array;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
188 pum_size = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
189
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
190 /* Set selected item and redraw. If the window size changed need to redo
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
191 * the positioning. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
192 if (pum_set_selected(selected))
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
193 goto redo;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
194 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
195
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
196 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
197 * Redraw the popup menu, using "pum_first" and "pum_selected".
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
198 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
199 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
200 pum_redraw()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
201 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
202 int row = pum_row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
203 int col;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
204 int attr_norm = highlight_attr[HLF_PNI];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
205 int attr_select = highlight_attr[HLF_PSI];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
206 int attr_scroll = highlight_attr[HLF_PSB];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
207 int attr_thumb = highlight_attr[HLF_PST];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
208 int attr;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
209 int i;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
210 int idx;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
211 char_u *s;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
212 char_u *p;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
213 int totwidth, width, w;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
214 int thumb_pos = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
215 int thumb_heigth = 1;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
216 int round;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
217 int n;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
218
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
219 if (pum_scrollbar)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
220 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
221 thumb_heigth = pum_height * pum_height / pum_size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
222 if (thumb_heigth == 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
223 thumb_heigth = 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
224 thumb_pos = (pum_first * (pum_height - thumb_heigth)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
225 + (pum_size - pum_height) / 2)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
226 / (pum_size - pum_height);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
227 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
228
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
229 for (i = 0; i < pum_height; ++i)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
230 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
231 idx = i + pum_first;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
232 attr = (idx == pum_selected) ? attr_select : attr_norm;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
233
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
234 /* prepend a space if there is room */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
235 if (pum_col > 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
236 screen_putchar(' ', row, pum_col - 1, attr);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
237
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
238 /* Display each entry, use two spaces for a Tab.
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
239 * Do this 3 times: For the main text, kind and extra info */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
240 col = pum_col;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
241 totwidth = 0;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
242 for (round = 1; round <= 3; ++round)
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
243 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
244 width = 0;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
245 s = NULL;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
246 switch (round)
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
247 {
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
248 case 1: p = pum_array[idx].pum_text; break;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
249 case 2: p = pum_array[idx].pum_kind; break;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
250 case 3: p = pum_array[idx].pum_extra; break;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
251 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
252 if (p != NULL)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
253 for ( ; ; mb_ptr_adv(p))
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
254 {
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
255 if (s == NULL)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
256 s = p;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
257 w = ptr2cells(p);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
258 if (*p == NUL || *p == TAB || totwidth + w > pum_width)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
259 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
260 /* Display the text that fits or comes before a Tab. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
261 screen_puts_len(s, p - s, row, col, attr);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
262 col += width;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
263
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
264 if (*p != TAB)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
265 break;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
266
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
267 /* Display two spaces for a Tab. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
268 screen_puts_len((char_u *)" ", 2, row, col, attr);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
269 col += 2;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
270 totwidth += 2;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
271 s = NULL; /* start text at next char */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
272 width = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
273 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
274 else
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
275 width += w;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
276 }
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
277
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
278 if (round > 1)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
279 n = pum_kind_width + 1;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
280 else
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
281 n = 1;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
282
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
283 /* Stop when there is nothing more to display. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
284 if (round == 3
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
285 || (round == 2 && pum_array[idx].pum_extra == NULL)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
286 || (round == 1 && pum_array[idx].pum_kind == NULL
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
287 && pum_array[idx].pum_extra == NULL)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
288 || pum_base_width + n >= pum_width)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
289 break;
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
290 screen_fill(row, row + 1, col, pum_col + pum_base_width + n,
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
291 ' ', ' ', attr);
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
292 col = pum_col + pum_base_width + n;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
293 totwidth = pum_base_width + n;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
294 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
295
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
296 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
297 if (pum_scrollbar > 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
298 screen_putchar(' ', row, pum_col + pum_width,
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
299 i >= thumb_pos && i < thumb_pos + thumb_heigth
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
300 ? attr_thumb : attr_scroll);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
301
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
302 ++row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
303 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
304 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
305
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
306 #if 0 /* not used yet */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
307 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
308 * Return the index of the currently selected item.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
309 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
310 int
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
311 pum_get_selected()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
312 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
313 return pum_selected;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
314 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
315 #endif
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
316
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
317 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
318 * Set the index of the currently selected item. The menu will scroll when
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
319 * necessary. When "n" is out of range don't scroll.
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
320 * Returns TRUE when the window was resized and the location of the popup menu
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
321 * must be recomputed.
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
322 */
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
323 static int
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
324 pum_set_selected(n)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
325 int n;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
326 {
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
327 int resized = FALSE;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
328
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
329 pum_selected = n;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
330
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
331 if (pum_selected >= 0 && pum_selected < pum_size)
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
332 {
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
333 if (pum_first > pum_selected - 4)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
334 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
335 /* scroll down; when we did a jump it's probably a PageUp then
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
336 * scroll a whole page */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
337 if (pum_first > pum_selected - 2)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
338 {
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
339 pum_first -= pum_height - 2;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
340 if (pum_first < 0)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
341 pum_first = 0;
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
342 else if (pum_first > pum_selected)
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
343 pum_first = pum_selected;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
344 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
345 else
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
346 pum_first = pum_selected;
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
347 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
348 else if (pum_first < pum_selected - pum_height + 5)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
349 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
350 /* scroll up; when we did a jump it's probably a PageDown then
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
351 * scroll a whole page */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
352 if (pum_first < pum_selected - pum_height + 1 + 2)
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
353 {
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
354 pum_first += pum_height - 2;
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
355 if (pum_first < pum_selected - pum_height + 1)
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
356 pum_first = pum_selected - pum_height + 1;
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
357 }
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
358 else
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
359 pum_first = pum_selected - pum_height + 1;
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
360 }
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
361
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
362 if (pum_height > 6)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
363 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
364 /* Give three lines of context when possible. */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
365 if (pum_first > pum_selected - 3)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
366 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
367 /* scroll down */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
368 pum_first = pum_selected - 3;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
369 if (pum_first < 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
370 pum_first = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
371 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
372 else if (pum_first < pum_selected + 3 - pum_height + 1)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
373 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
374 /* scroll up */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
375 pum_first = pum_selected + 3 - pum_height + 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
376 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
377 }
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
378
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
379 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
380 /* Show extra info in the preview window if there is something and
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
381 * 'completeopt' contains "preview". */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
382 if (pum_array[pum_selected].pum_info != NULL
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
383 && vim_strchr(p_cot, 'p') != NULL)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
384 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
385 win_T *curwin_save = curwin;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
386 int res = OK;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
387
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
388 /* Open a preview window. 3 lines by default. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
389 g_do_tagpreview = 3;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
390 resized = prepare_tagpreview();
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
391 g_do_tagpreview = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
392
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
393 if (curwin->w_p_pvw)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
394 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
395 if (curbuf->b_fname == NULL
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
396 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f'
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
397 && curbuf->b_p_bh[0] == 'w')
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
398 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
399 /* Already a "wipeout" buffer, make it empty. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
400 while (!bufempty())
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
401 ml_delete((linenr_T)1, FALSE);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
402 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
403 else if ((res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0))
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
404 == OK)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
405 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
406 /* Edit a new, empty buffer. Set options for a "wipeout"
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
407 * buffer. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
408 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
409 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile",
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
410 OPT_LOCAL);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
411 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe",
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
412 OPT_LOCAL);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
413 set_option_value((char_u *)"diff", 0L, (char_u *)"",
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
414 OPT_LOCAL);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
415 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
416 if (res == OK)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
417 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
418 char_u *p, *e;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
419 linenr_T lnum = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
420
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
421 for (p = pum_array[pum_selected].pum_info; *p != NUL; )
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
422 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
423 e = vim_strchr(p, '\n');
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
424 if (e == NULL)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
425 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
426 ml_append(lnum++, p, 0, FALSE);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
427 break;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
428 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
429 else
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
430 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
431 *e = NUL;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
432 ml_append(lnum++, p, e - p + 1, FALSE);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
433 *e = '\n';
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
434 p = e + 1;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
435 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
436 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
437
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
438 /* Increase the height of the preview window to show the
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
439 * text, but no more than 'previewheight' lines. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
440 if (lnum > p_pvh)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
441 lnum = p_pvh;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
442 if (curwin->w_height < lnum)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
443 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
444 win_setheight((int)lnum);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
445 resized = TRUE;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
446 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
447
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
448 curbuf->b_changed = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
449 curbuf->b_p_ma = FALSE;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
450 curwin->w_cursor.lnum = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
451 curwin->w_cursor.col = 0;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
452
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
453 if (curwin != curwin_save && win_valid(curwin_save))
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
454 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
455 /* Return cursor to where we were */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
456 validate_cursor();
743
afac7b58ed46 updated for version 7.0222
vimboss
parents: 730
diff changeset
457 redraw_later(SOME_VALID);
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
458
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
459 /* When the preview window was resized we need to
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
460 * update the view on the buffer. Only go back to
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
461 * the window when needed, otherwise it will always be
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
462 * redraw. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
463 if (resized)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
464 {
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
465 win_enter(curwin_save, TRUE);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
466 update_topline();
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
467 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
468
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
469 /* Update the screen before drawing the popup menu.
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
470 * Enable updating the status lines. */
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
471 pum_do_redraw = TRUE;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
472 update_screen(0);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
473 pum_do_redraw = FALSE;
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
474
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
475 if (win_valid(curwin_save))
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
476 win_enter(curwin_save, TRUE);
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
477 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
478 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
479 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
480 }
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
481 #endif
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
482 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
483
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
484 /* Never display more than we have */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
485 if (pum_first > pum_size - pum_height)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
486 pum_first = pum_size - pum_height;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
487
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
488 if (!resized)
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
489 pum_redraw();
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
490
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
491 return resized;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
492 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
493
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
494 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
495 * Undisplay the popup menu (later).
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
496 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
497 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
498 pum_undisplay()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
499 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
500 pum_array = NULL;
743
afac7b58ed46 updated for version 7.0222
vimboss
parents: 730
diff changeset
501 redraw_all_later(SOME_VALID);
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
502 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
503
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
504 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
505 * Clear the popup menu. Currently only resets the offset to the first
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
506 * displayed item.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
507 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
508 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
509 pum_clear()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
510 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
511 pum_first = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
512 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
513
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
514 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
515 * Return TRUE if the popup menu is displayed.
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
516 * Overruled when "pum_do_redraw" is set, used to redraw the status lines.
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
517 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
518 int
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
519 pum_visible()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
520 {
730
44348703ab1b updated for version 7.0221
vimboss
parents: 716
diff changeset
521 return !pum_do_redraw && pum_array != NULL;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
522 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
523
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
524 /*
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
525 * Return the height of the popup menu, the number of entries visible.
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
526 * Only valid when pum_visible() returns TRUE!
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
527 */
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
528 int
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
529 pum_get_height()
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
530 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
531 return pum_height;
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
532 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
533
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
534 #endif