|
| 1 | + |
1 | 2 | /****************************************************************************** |
2 | 3 | * MODULE : edit_complete.cpp |
3 | 4 | * DESCRIPTION: Tab completion |
@@ -57,6 +58,7 @@ find_completions (drd_info drd, tree t, hashset<string>& h, string prefix= "") { |
57 | 58 | static array<string> |
58 | 59 | find_completions (drd_info drd, tree t, string prefix= "") { |
59 | 60 | hashset<string> h; |
| 61 | + h->insert (string("")); |
60 | 62 | find_completions (drd, t, h, prefix); |
61 | 63 | return as_completions (h); |
62 | 64 | } |
@@ -132,34 +134,36 @@ edit_interface_rep::complete_start (string prefix, array<string> compls) { |
132 | 134 | completion_prefix= prefix; |
133 | 135 | completions = close_completions (compls); |
134 | 136 | completion_pos = 0; |
135 | | - bool visible; |
136 | | - SERVER (get_completion_listbox_visible (visible)) |
137 | | - if (!visible) { |
138 | | - // TODO: refactor this part to edit_interface_rep::show_completion_listbox |
| 137 | + { |
| 138 | + // TODO: ?refactor this part to edit_interface_rep::show_completion_listbox |
| 139 | + cout << "complete_start: " |
| 140 | + << "completions=" << completions |
| 141 | + << ", prefix=" << completion_prefix |
| 142 | + << ", tp=" << tp |
| 143 | + << ", et=" << et |
| 144 | + << ", eb=" << eb |
| 145 | + << LF; |
139 | 146 | array<string> full_completions; |
140 | 147 | for (int i= 0; i < N (completions); ++i) { |
| 148 | + cout << "complete_start: completions[" << i << "]=" << completions[i] << LF; |
141 | 149 | string c= completions[i]; |
142 | | - if (c == completion_prefix) continue; // skip the prefix itself |
143 | 150 | full_completions << (completion_prefix * c); |
144 | 151 | } |
145 | | - |
146 | 152 | path tp1= tp; |
147 | 153 | for (int i= 0; i < N (prefix); ++i) { |
148 | 154 | tp1= previous_valid (et, tp1); |
149 | 155 | } |
150 | | - |
151 | 156 | cursor cu= eb->find_check_cursor (tp1); |
152 | | - // cout << "Prefix Cursor: " << cu->ox << ", " << cu->oy << LF; |
153 | | - SI pos_x= |
154 | | - ((cu->ox - get_scroll_x () - 500) * magf + get_canvas_x ()) / 256; |
155 | | - SI pos_y= -((cu->oy - 5000 - get_scroll_y ()) * magf) / 256; |
156 | | - // TODO: 5000 is a magic number to add space between completion list box |
157 | | - // and the text. |
158 | | - // We need to find a better way to get the position |
159 | | - |
160 | | - SERVER (show_completion_listbox (full_completions, pos_x, pos_y)); |
| 157 | + cout << "show_completion_listbox: " |
| 158 | + << "completions=" << full_completions |
| 159 | + << ", cu->ox=" << cu->ox |
| 160 | + << ", cu->oy=" << cu->oy |
| 161 | + << ", magf=" << magf |
| 162 | + << ", scroll_x=" << get_scroll_x () |
| 163 | + << ", scroll_y=" << get_scroll_y () |
| 164 | + << ", canvas_x=" << get_canvas_x () << LF; |
| 165 | + show_completion_listbox (tp, full_completions, cu, magf, get_scroll_x(), get_scroll_y(), get_canvas_x()); |
161 | 166 | } |
162 | | - |
163 | 167 | insert_tree (completions[0]); |
164 | 168 | complete_message (); |
165 | 169 | beep (); |
@@ -199,19 +203,20 @@ edit_interface_rep::complete_keypress (string key) { |
199 | 203 |
|
200 | 204 | if (key == "tab" || key == "down") { |
201 | 205 | completion_pos++; |
202 | | - SERVER (set_completion_listbox_next (true)); |
| 206 | + completion_listbox_next (true); |
203 | 207 | } |
204 | 208 | else if (key == "S-tab" || key == "up") { |
205 | 209 | completion_pos--; |
206 | | - SERVER (set_completion_listbox_next (false)); |
| 210 | + completion_listbox_next (false); |
207 | 211 | } |
208 | 212 | if (completion_pos < 0) completion_pos= N (completions) - 1; |
209 | 213 | if (completion_pos >= N (completions)) completion_pos= 0; |
210 | | - SERVER (set_completion_listbox_visible (true)) |
211 | 214 | string new_s= completions[completion_pos]; |
212 | 215 | remove (path_up (tp) * (end - N (old_s)), N (old_s)); |
213 | 216 | insert (path_up (tp) * (end - N (old_s)), new_s); |
214 | 217 | complete_message (); |
| 218 | + apply_changes(); // sync eb, for calculating the new cursor position |
| 219 | + update_completion_listbox_position (et, eb, tp, magf, get_scroll_x(), get_scroll_y(), get_canvas_x(), completion_pos); |
215 | 220 | return true; |
216 | 221 | } |
217 | 222 |
|
@@ -268,6 +273,7 @@ edit_interface_rep::custom_complete (tree r) { |
268 | 273 | int i, n= N (r); |
269 | 274 | string prefix; |
270 | 275 | array<string> compls; |
| 276 | + compls << string (""); |
271 | 277 | for (i= 0; i < n; i++) |
272 | 278 | if (is_atomic (r[i])) { |
273 | 279 | string l= r[i]->label; |
|
0 commit comments