@@ -87,15 +87,22 @@ edit_interface_rep::complete_try () {
8787 }
8888 else {
8989 if ((end == 0 ) || (!is_iso_alpha (s[end - 1 ])) ||
90- ((end != N (s)) && is_iso_alpha (s[end])))
90+ ((end != N (s)) && is_iso_alpha (s[end]))) {
91+ set_input_normal ();
92+ SERVER (set_completion_listbox_visible (false ));
9193 return false ;
94+ }
9295 int start= end - 1 ;
9396 while ((start > 0 ) && is_iso_alpha (s[start - 1 ]))
9497 start--;
9598 ss= s (start, end);
9699 a = find_completions (drd, et, ss);
97100 }
98- if (N (a) == 0 ) return false ;
101+ if (N (a) <= 1 ) {
102+ set_input_normal ();
103+ SERVER (set_completion_listbox_visible (false ));
104+ return false ;
105+ }
99106 complete_start (ss, a);
100107 return true ;
101108}
@@ -123,25 +130,18 @@ edit_interface_rep::complete_start (string prefix, array<string> compls) {
123130 if ((end < N (prefix)) || (s (end - N (prefix), end) != prefix)) return ;
124131
125132 // perform first completion and switch to completion mode if necessary
126- if (N (compls) == 1 ) {
127- string s= compls[0 ];
128- if (ends (s, " ()" )) // temporary fix for Pari
129- insert_tree (s, path (N (s) - 1 ));
130- else insert_tree (s);
131- completions= array<string> ();
132- }
133- else {
133+ {
134134 completion_prefix= prefix;
135135 completions = close_completions (compls);
136136 completion_pos = 0 ;
137137 {
138138 // TODO: ?refactor this part to edit_interface_rep::show_completion_listbox
139139 cout << " complete_start: "
140- << " completions=" << completions
141- << " , prefix=" << completion_prefix
142- << " , tp=" << tp
143- << " , et=" << et
144- << " , eb=" << eb
140+ // << "completions=" << completions
141+ << " , prefix=" << completion_prefix
142+ // << ", tp=" << tp
143+ // << ", et=" << et
144+ // << ", eb=" << eb
145145 << LF;
146146 array<string> full_completions;
147147 for (int i= 0 ; i < N (completions); ++i) {
@@ -166,7 +166,7 @@ edit_interface_rep::complete_start (string prefix, array<string> compls) {
166166 }
167167 insert_tree (completions[0 ]);
168168 complete_message ();
169- beep ();
169+ // beep ();
170170 set_input_mode (INPUT_COMPLETE);
171171 }
172172}
@@ -182,11 +182,16 @@ edit_interface_rep::complete_keypress (string key) {
182182 SERVER (set_completion_listbox_visible (false ));
183183 return true ;
184184 }
185- if (( key != " tab " ) && (key ! = " S-tab " ) && ( key != " up " ) && (key != " down " ) ) {
185+ else if (key = = " escape " || key == " " ) {
186186 set_input_normal ();
187187 SERVER (set_completion_listbox_visible (false ));
188188 return false ;
189189 }
190+ else if ((key != " tab" ) && (key != " S-tab" ) && (key != " up" ) && (key != " down" )) {
191+ // set_input_normal ();
192+ // SERVER (set_completion_listbox_visible (false));
193+ return false ;
194+ }
190195 tree st= subtree (et, path_up (tp));
191196 if (is_compound (st)) {
192197 set_input_normal ();
@@ -272,7 +277,7 @@ edit_interface_rep::custom_complete (tree r) {
272277 if (!is_tuple (r)) return ;
273278 int i, n= N (r);
274279 string prefix;
275- array <string> compls;
280+ hashset <string> compls;
276281 compls << string (" " );
277282 for (i= 0 ; i < n; i++)
278283 if (is_atomic (r[i])) {
@@ -283,8 +288,12 @@ edit_interface_rep::custom_complete (tree r) {
283288 }
284289 // cout << prefix << ", " << compls << LF;
285290
286- if ((prefix == " " ) || (N (compls) == 0 )) return ;
287- complete_start (prefix, compls);
291+ if ((prefix == " " ) || (N (compls) <= 1 )) {
292+ set_input_normal ();
293+ SERVER (set_completion_listbox_visible (false ));
294+ return ;
295+ }
296+ complete_start (prefix, as_completions (compls));
288297}
289298
290299/* *****************************************************************************
0 commit comments