* @return true, if the textbuf was updated. */
| 21 | * @return true, if the textbuf was updated. |
| 22 | */ |
| 23 | bool AutoCompletion::AutoComplete() |
| 24 | { |
| 25 | /* We are pressing TAB for the first time after reset. */ |
| 26 | if (this->suggestions.empty()) { |
| 27 | this->InitSuggestions(this->textbuf->GetText()); |
| 28 | if (this->suggestions.empty()) { |
| 29 | return false; |
| 30 | } |
| 31 | this->ApplySuggestion(prefix, suggestions[0]); |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | /* We are pressing TAB again on the same text. */ |
| 36 | if (this->current_suggestion_index + 1 < this->suggestions.size()) { |
| 37 | this->ApplySuggestion(prefix, this->suggestions[++this->current_suggestion_index]); |
| 38 | } else { |
| 39 | /* We are out of options, restore original text. */ |
| 40 | this->textbuf->Assign(initial_buf); |
| 41 | this->Reset(); |
| 42 | } |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | void AutoCompletion::Reset() |
| 47 | { |
no test coverage detected