Stop centering clicked suggestions in the autocomplete popup

This commit is contained in:
Michael Alexsander 2022-10-28 21:05:40 -03:00
parent 28afd32d29
commit 7a682236df
2 changed files with 16 additions and 2 deletions

View file

@ -1691,7 +1691,7 @@ void TextEdit::_notification(int p_what) {
const int icon_area_width = icon_area_size.width + icon_hsep; const int icon_area_width = icon_area_size.width + icon_hsep;
width += icon_area_size.width + icon_hsep; width += icon_area_size.width + icon_hsep;
const int line_from = CLAMP(completion_index - row_count / 2, 0, completion_options_size - row_count); const int line_from = CLAMP((completion_force_item_center < 0 ? completion_index : completion_force_item_center) - row_count / 2, 0, completion_options_size - row_count);
for (int i = 0; i < row_count; i++) { for (int i = 0; i < row_count; i++) {
int l = line_from + i; int l = line_from + i;
@ -2417,6 +2417,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (completion_index > 0) { if (completion_index > 0) {
completion_index--; completion_index--;
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
} }
} }
@ -2424,13 +2425,17 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (completion_index < completion_options.size() - 1) { if (completion_index < completion_options.size() - 1) {
completion_index++; completion_index++;
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
} }
} }
if (mb->get_button_index() == BUTTON_LEFT) { if (mb->get_button_index() == BUTTON_LEFT) {
completion_index = CLAMP(completion_line_ofs + (mb->get_position().y - completion_rect.position.y) / get_row_height(), 0, completion_options.size() - 1); if (completion_force_item_center == -1) {
completion_force_item_center = completion_index;
}
completion_index = CLAMP(completion_line_ofs + (mb->get_position().y - completion_rect.position.y) / get_row_height(), 0, completion_options.size() - 1);
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
update(); update();
if (mb->is_doubleclick()) { if (mb->is_doubleclick()) {
@ -2826,6 +2831,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
completion_index = completion_options.size() - 1; completion_index = completion_options.size() - 1;
} }
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
accept_event(); accept_event();
@ -2839,6 +2845,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
completion_index = 0; completion_index = 0;
} }
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
accept_event(); accept_event();
@ -2851,6 +2858,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
completion_index = 0; completion_index = 0;
} }
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
accept_event(); accept_event();
return; return;
@ -2862,6 +2870,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
completion_index = completion_options.size() - 1; completion_index = completion_options.size() - 1;
} }
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
accept_event(); accept_event();
return; return;
@ -2870,6 +2879,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_scancode() == KEY_HOME && completion_index > 0) { if (k->get_scancode() == KEY_HOME && completion_index > 0) {
completion_index = 0; completion_index = 0;
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
accept_event(); accept_event();
return; return;
@ -2878,6 +2888,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_scancode() == KEY_END && completion_index < completion_options.size() - 1) { if (k->get_scancode() == KEY_END && completion_index < completion_options.size() - 1) {
completion_index = completion_options.size() - 1; completion_index = completion_options.size() - 1;
completion_current = completion_options[completion_index]; completion_current = completion_options[completion_index];
completion_force_item_center = -1;
update(); update();
accept_event(); accept_event();
return; return;
@ -6922,6 +6933,7 @@ void TextEdit::_update_completion_candidates() {
completion_options.clear(); completion_options.clear();
completion_index = 0; completion_index = 0;
completion_force_item_center = -1;
completion_base = s; completion_base = s;
Vector<float> sim_cache; Vector<float> sim_cache;
bool single_quote = s.begins_with("'"); bool single_quote = s.begins_with("'");
@ -7035,6 +7047,7 @@ void TextEdit::code_complete(const List<ScriptCodeCompletionOption> &p_strings,
completion_forced = p_forced; completion_forced = p_forced;
completion_current = ScriptCodeCompletionOption(); completion_current = ScriptCodeCompletionOption();
completion_index = 0; completion_index = 0;
completion_force_item_center = -1;
_update_completion_candidates(); _update_completion_candidates();
} }

View file

@ -333,6 +333,7 @@ private:
ScriptCodeCompletionOption completion_current; ScriptCodeCompletionOption completion_current;
String completion_base; String completion_base;
int completion_index; int completion_index;
int completion_force_item_center;
Rect2i completion_rect; Rect2i completion_rect;
int completion_line_ofs; int completion_line_ofs;
String completion_hint; String completion_hint;