Skip to content

Commit

Permalink
wip occurrence color
Browse files Browse the repository at this point in the history
- prefer occurrence with higher match

-> odo
"aodo"
"od2o"
  • Loading branch information
AlexHolly committed Sep 16, 2019
1 parent ad1946a commit 8be633b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ void EditorSettings::_load_default_text_editor_theme() {
_initial_set("text_editor/highlighting/completion_existing_color", Color(0.13, 0.87, 0.87, 0.87));
_initial_set("text_editor/highlighting/completion_scroll_color", Color(1, 1, 1));
_initial_set("text_editor/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
_initial_set("text_editor/highlighting/completion_occurrences_color", Color(0.3, 0.3, 0.3));
_initial_set("text_editor/highlighting/text_color", Color(0.67, 0.67, 0.67));
_initial_set("text_editor/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4));
_initial_set("text_editor/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6));
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void TextEditor::_load_theme_settings() {
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
Color completion_occurrences_color = EDITOR_GET("text_editor/highlighting/completion_occurrences_color");
Color number_color = EDITOR_GET("text_editor/highlighting/number_color");
Color function_color = EDITOR_GET("text_editor/highlighting/function_color");
Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
Expand Down Expand Up @@ -122,6 +123,7 @@ void TextEditor::_load_theme_settings() {
text_edit->add_color_override("current_line_color", current_line_color);
text_edit->add_color_override("line_length_guideline_color", line_length_guideline_color);
text_edit->add_color_override("word_highlighted_color", word_highlighted_color);
text_edit->add_color_override("completion_occurrences_color", completion_occurrences_color);
text_edit->add_color_override("number_color", number_color);
text_edit->add_color_override("function_color", function_color);
text_edit->add_color_override("member_variable_color", member_variable_color);
Expand Down
6 changes: 2 additions & 4 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4726,6 +4726,7 @@ void TextEdit::_update_caches() {
cache.completion_selected_color = get_color("completion_selected_color");
cache.completion_existing_color = get_color("completion_existing_color");
cache.completion_font_color = get_color("completion_font_color");
cache.completion_occurrences_color = get_color("completion_occurrences_color");
cache.font = get_font("font");
cache.caret_color = get_color("caret_color");
cache.caret_background_color = get_color("caret_background_color");
Expand Down Expand Up @@ -6303,22 +6304,19 @@ void TextEdit::_update_completion_candidates() {
int maxlines = get_constant("completion_lines");
int cmax_width = (get_constant("completion_max_width") * cache.font->get_char_size('x').x);
int scrollw = get_constant("completion_scroll_width");
Color text_color = get_color("word_highlighted_color");

completion->clear();

for (int i = 0; i < completion_options.size(); i++) {
ScriptCodeCompletionOption option = completion_options[i];
completion->add_icon_item(option.icon);
completion->set_item_text(i, option.display);
completion->set_item_custom_hl_color(completion->get_item_count() - 1, Color(1, 0, 0));
Array columns_hl;
for (int j = 0; j < option.occurrences.size(); j++) {
for (int k = (int)((Array)((Array)option.occurrences[j])[1])[0]; k <= (int)((Array)((Array)option.occurrences[j])[1])[1]; k++) {
columns_hl.push_back(k);
}
}
completion->set_item_custom_hl_color(completion->get_item_count() - 1, text_color);
completion->set_item_custom_hl_color(completion->get_item_count() - 1, cache.completion_occurrences_color);
completion->set_item_highlights(completion->get_item_count() - 1, columns_hl);
}

Expand Down
20 changes: 14 additions & 6 deletions scene/gui/text_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class TextEdit : public Control {
Color completion_selected_color;
Color completion_existing_color;
Color completion_font_color;
Color completion_occurrences_color;
Color caret_color;
Color caret_background_color;
Color line_number_color;
Expand Down Expand Up @@ -489,9 +490,9 @@ class TextEdit : public Control {

struct SortOptions {
bool operator()(ScriptCodeCompletionOption p_a, ScriptCodeCompletionOption p_b) const {
//Hack check case for first character
// Hack check case for first character
String input = p_a.input.substr(0, 1);
if (input != p_a.input.substr(0, 1).to_lower()) { //input is upper -> prefer upper results
if (input != p_a.input.substr(0, 1).to_lower()) { // input is upper -> prefer upper results
if ((int)((Array)((Array)p_a.occurrences[0])[1])[0] == 0 &&
(int)((Array)((Array)p_b.occurrences[0])[1])[0] == 0) {
if (p_a.insert_text.substr(0, 1) != p_b.insert_text.substr(0, 1)) {
Expand All @@ -501,14 +502,21 @@ class TextEdit : public Control {
}
int min_size = p_a.occurrences.size() < p_b.occurrences.size() ? p_a.occurrences.size() : p_b.occurrences.size();
for (int i = 0; i < min_size; i++) {
if (((Array)((Array)p_a.occurrences[i])[1])[0] < ((Array)((Array)p_b.occurrences[i])[1])[0])
print_line(((String)((Array)p_a.occurrences[i])[0]));
print_line(((String)((Array)p_b.occurrences[i])[0]));
if (((String)((Array)p_a.occurrences[i])[0]).size() < ((String)((Array)p_b.occurrences[i])[0]).size()) { // prefer occurrence with higher match
return false;
} else if (((String)((Array)p_a.occurrences[i])[0]).size() > ((String)((Array)p_b.occurrences[i])[0]).size()) {
return true;
} else if (((Array)((Array)p_a.occurrences[i])[1])[0] < ((Array)((Array)p_b.occurrences[i])[1])[0]) { // different length, prefer closer to start
return true;
else if (((Array)((Array)p_b.occurrences[i])[1])[0] < ((Array)((Array)p_a.occurrences[i])[1])[0])
} else if (((Array)((Array)p_b.occurrences[i])[1])[0] < ((Array)((Array)p_a.occurrences[i])[1])[0]) {
return false;
else if (((Array)((Array)p_b.occurrences[i])[1])[1] < ((Array)((Array)p_a.occurrences[i])[1])[1])
} else if (((Array)((Array)p_b.occurrences[i])[1])[1] < ((Array)((Array)p_a.occurrences[i])[1])[1]) {
return true;
else if (((Array)((Array)p_a.occurrences[i])[1])[1] < ((Array)((Array)p_b.occurrences[i])[1])[1])
} else if (((Array)((Array)p_a.occurrences[i])[1])[1] < ((Array)((Array)p_b.occurrences[i])[1])[1]) {
return false;
}
}

// sort by alphabet if same length
Expand Down
1 change: 1 addition & 0 deletions scene/resources/default_theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("completion_existing_color", "TextEdit", Color(0.87, 0.87, 0.87, 0.13));
theme->set_color("completion_scroll_color", "TextEdit", control_font_color_pressed);
theme->set_color("completion_font_color", "TextEdit", Color(0.67, 0.67, 0.67));
theme->set_color("completion_occurrences_color", "TextEdit", Color(0.3, 0.3, 0.3));
theme->set_color("font_color", "TextEdit", control_font_color);
theme->set_color("font_color_selected", "TextEdit", Color(0, 0, 0));
theme->set_color("font_color_readonly", "TextEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f));
Expand Down

0 comments on commit 8be633b

Please sign in to comment.