Merge pull request #20586 from AlexHolly/text-edit-auto-completion

text_edit auto_completion
This commit is contained in:
Rémi Verschelde 2018-08-24 20:48:01 +02:00 committed by GitHub
commit 6ce4078c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 34 deletions

View File

@ -5640,6 +5640,10 @@ void TextEdit::_confirm_completion() {
end_complex_operation(); end_complex_operation();
_cancel_completion(); _cancel_completion();
if (last_completion_char == '(') {
query_code_comple();
}
} }
void TextEdit::_cancel_code_hint() { void TextEdit::_cancel_code_hint() {
@ -5751,43 +5755,23 @@ void TextEdit::_update_completion_candidates() {
completion_strings.write[i] = completion_strings[i].unquote().quote("'"); completion_strings.write[i] = completion_strings[i].unquote().quote("'");
} }
if (s == completion_strings[i]) { if (completion_strings[i].begins_with(s)) {
// A perfect match, stop completion completion_options.push_back(completion_strings[i]);
_cancel_completion();
return;
} }
}
if (s.is_subsequence_ofi(completion_strings[i])) { if (completion_options.size() == 0) {
// don't remove duplicates if no input is provided for (int i = 0; i < completion_strings.size(); i++) {
if (s != "" && completion_options.find(completion_strings[i]) != -1) { if (s.is_subsequence_of(completion_strings[i])) {
continue; completion_options.push_back(completion_strings[i]);
} }
// Calculate the similarity to keep completions in good order }
float similarity; }
if (completion_strings[i].begins_with(s)) {
// Substrings (same case) are the best candidates if (completion_options.size() == 0) {
similarity = 1.2; for (int i = 0; i < completion_strings.size(); i++) {
} else if (completion_strings[i].to_lower().begins_with(s.to_lower())) { if (s.is_subsequence_ofi(completion_strings[i])) {
// then any substrings
similarity = 1.1;
} else {
// Otherwise compute the similarity
similarity = s.to_lower().similarity(completion_strings[i].to_lower());
}
int comp_size = completion_options.size();
if (comp_size == 0) {
completion_options.push_back(completion_strings[i]); completion_options.push_back(completion_strings[i]);
sim_cache.push_back(similarity);
} else {
float comp_sim;
int pos = 0;
do {
comp_sim = sim_cache[pos++];
} while (pos < comp_size && similarity < comp_sim);
pos = similarity > comp_sim ? pos - 1 : pos; // Pos will be off by one
completion_options.insert(pos, completion_strings[i]);
sim_cache.insert(pos, similarity);
} }
} }
} }
@ -5795,7 +5779,12 @@ void TextEdit::_update_completion_candidates() {
if (completion_options.size() == 0) { if (completion_options.size() == 0) {
//no options to complete, cancel //no options to complete, cancel
_cancel_completion(); _cancel_completion();
return;
}
if (completion_options.size() == 1 && s == completion_options[0]) {
// A perfect match, stop completion
_cancel_completion();
return; return;
} }