From 805b668d7f7a5fcddf887e25938f6ee829bd19d8 Mon Sep 17 00:00:00 2001 From: George Marques Date: Sun, 3 Jul 2016 11:32:30 -0300 Subject: Fix code completion sorting --- scene/gui/text_edit.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'scene/gui/text_edit.cpp') diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index e106f0dfc6..18552c0776 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4146,7 +4146,15 @@ void TextEdit::_update_completion_candidates() { continue; } // Calculate the similarity to keep completions in good order - float similarity = s.similarity(completion_strings[i]); + float similarity; + if (completion_strings[i].to_lower().begins_with(s.to_lower())) { + // Substrings are the best candidates + 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]); @@ -4156,8 +4164,8 @@ void TextEdit::_update_completion_candidates() { int pos = 0; do { comp_sim = sim_cache[pos++]; - } while(pos < comp_size && similarity <= comp_sim); - pos--; // Pos will be off by one + } 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); } -- cgit v1.2.3 From ec18b97f5cdc3fcf67cb2625d289cb061958b2b6 Mon Sep 17 00:00:00 2001 From: George Marques Date: Sun, 3 Jul 2016 11:34:23 -0300 Subject: Stop completion when the match is perfect to avoid the completion insisting showing up after a completion. --- scene/gui/text_edit.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'scene/gui/text_edit.cpp') diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 18552c0776..40fc9a70cc 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4140,6 +4140,11 @@ void TextEdit::_update_completion_candidates() { int ci_match=0; Vector sim_cache; for(int i=0;i