- // complete or increment the command
- string const s(lyxaction.getApproxFuncName(fl_get_input(ob)));
- if (!s.empty())
- fl_set_input(ob, s.c_str());
- return 1;
+ // Completion handling.
+
+ vector<string> comp;
+ lyx::copy_if(completion_.begin(),
+ completion_.end(),
+ back_inserter(comp), prefix(input));
+
+ if (comp.empty()) {
+ // No matches
+ string const tmp = input + _(" [no match]");
+ stored_set(input);
+ set_input(tmp);
+ } else if (comp.size() == 1) {
+ // Perfect match
+ string const tmp =
+ comp[0] + _(" [sole completion]");
+ stored_set(comp[0] + " ");
+ set_input(tmp);
+ } else {
+ // More that one match
+ // Find maximal avaliable prefix
+ string const tmp = comp[0];
+ string test(input);
+ if (tmp.length() > test.length())
+ test += tmp[test.length()];
+ while (test.length() < tmp.length()) {
+ vector<string> vtmp;
+ lyx::copy_if(comp.begin(),
+ comp.end(),
+ back_inserter(vtmp),
+ prefix(test));
+ if (vtmp.size() != comp.size()) {
+ test.erase(test.length() - 1);
+ break;
+ }
+ test += tmp[test.length()];
+ }
+ set_input(test);
+
+ int x,y,w,h;
+ fl_get_wingeometry(fl_get_real_object_window(the_buffer),
+ &x, &y, &w, &h);
+
+ // asynchronous completion
+ int const air = the_buffer->x;
+ x += air;
+ y += h - (the_buffer->h + air);
+ w = the_buffer->w;
+ dropdown_->select(comp, x, y, w);
+ }
+ return 1;