Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Fix code completion list scrolling with trackpad. #94363

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions scene/gui/code_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,27 @@ void CodeEdit::_notification(int p_what) {
}

void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventPanGesture> pan_gesture = p_gui_input;
if (pan_gesture.is_valid() && code_completion_active && code_completion_rect.has_point(pan_gesture->get_position())) {
const real_t delta = pan_gesture->get_delta().y;
code_completion_pan_offset += delta;
if (code_completion_pan_offset <= -1.0) {
if (code_completion_current_selected > 0) {
code_completion_current_selected--;
code_completion_force_item_center = -1;
queue_redraw();
}
code_completion_pan_offset += 1.0f;
} else if (code_completion_pan_offset >= +1.0) {
if (code_completion_current_selected < code_completion_options.size() - 1) {
code_completion_current_selected++;
code_completion_force_item_center = -1;
queue_redraw();
}
code_completion_pan_offset -= 1.0f;
}
}

Ref<InputEventMouseButton> mb = p_gui_input;
if (mb.is_valid()) {
// Ignore mouse clicks in IME input mode, let TextEdit handle it.
Expand Down Expand Up @@ -285,13 +306,15 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
if (code_completion_current_selected > 0) {
code_completion_current_selected--;
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
queue_redraw();
}
} break;
case MouseButton::WHEEL_DOWN: {
if (code_completion_current_selected < code_completion_options.size() - 1) {
code_completion_current_selected++;
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
queue_redraw();
}
} break;
Expand All @@ -301,6 +324,7 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
}

code_completion_current_selected = CLAMP(code_completion_line_ofs + (mb->get_position().y - code_completion_rect.position.y) / get_line_height(), 0, code_completion_options.size() - 1);
code_completion_pan_offset = 0.0f;
if (mb->is_double_click()) {
confirm_code_completion();
}
Expand Down Expand Up @@ -472,6 +496,7 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
code_completion_current_selected = code_completion_options.size() - 1;
}
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
queue_redraw();
accept_event();
return;
Expand All @@ -483,20 +508,23 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
code_completion_current_selected = 0;
}
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
queue_redraw();
accept_event();
return;
}
if (k->is_action("ui_page_up", true)) {
code_completion_current_selected = MAX(0, code_completion_current_selected - theme_cache.code_completion_max_lines);
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
queue_redraw();
accept_event();
return;
}
if (k->is_action("ui_page_down", true)) {
code_completion_current_selected = MIN(code_completion_options.size() - 1, code_completion_current_selected + theme_cache.code_completion_max_lines);
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
queue_redraw();
accept_event();
return;
Expand Down Expand Up @@ -2119,6 +2147,7 @@ void CodeEdit::set_code_completion_selected_index(int p_index) {
ERR_FAIL_INDEX(p_index, code_completion_options.size());
code_completion_current_selected = p_index;
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
queue_redraw();
}

Expand Down Expand Up @@ -3244,6 +3273,7 @@ void CodeEdit::_update_scroll_selected_line(float p_mouse_y) {

code_completion_current_selected = (int)(percent * (code_completion_options.size() - 1));
code_completion_force_item_center = -1;
code_completion_pan_offset = 0.0f;
}

void CodeEdit::_filter_code_completion_candidates_impl() {
Expand Down Expand Up @@ -3305,6 +3335,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() {

if (_should_reset_selected_option_for_new_options(code_completion_options_new)) {
code_completion_current_selected = 0;
code_completion_pan_offset = 0.0f;
}
code_completion_options = code_completion_options_new;

Expand Down Expand Up @@ -3520,6 +3551,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() {
code_completion_options_new.sort_custom<CodeCompletionOptionCompare>();
if (_should_reset_selected_option_for_new_options(code_completion_options_new)) {
code_completion_current_selected = 0;
code_completion_pan_offset = 0.0f;
}
code_completion_options = code_completion_options_new;

Expand Down
1 change: 1 addition & 0 deletions scene/gui/code_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class CodeEdit : public TextEdit {
int code_completion_longest_line = 0;
Rect2i code_completion_rect;
Rect2i code_completion_scroll_rect;
float code_completion_pan_offset = 0.0f;

HashSet<char32_t> code_completion_prefixes;
List<ScriptLanguage::CodeCompletionOption> code_completion_option_submitted;
Expand Down
Loading