RichTextLabel: proper handling of internal key events

Fixes #36211

(cherry picked from commit ff030afc93)
This commit is contained in:
Dominik 'dreamsComeTrue' Jasiński 2020-02-14 23:15:38 +01:00 committed by Rémi Verschelde
parent 1c9132540f
commit eb22bcead7
1 changed files with 20 additions and 10 deletions

View File

@ -1203,49 +1203,59 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
if (k.is_valid()) { if (k.is_valid()) {
if (k->is_pressed() && !k->get_alt() && !k->get_shift()) { if (k->is_pressed() && !k->get_alt() && !k->get_shift()) {
bool handled = true; bool handled = false;
switch (k->get_scancode()) { switch (k->get_scancode()) {
case KEY_PAGEUP: { case KEY_PAGEUP: {
if (vscroll->is_visible_in_tree()) if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() - vscroll->get_page()); vscroll->set_value(vscroll->get_value() - vscroll->get_page());
handled = true;
}
} break; } break;
case KEY_PAGEDOWN: { case KEY_PAGEDOWN: {
if (vscroll->is_visible_in_tree()) if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page()); vscroll->set_value(vscroll->get_value() + vscroll->get_page());
handled = true;
}
} break; } break;
case KEY_UP: { case KEY_UP: {
if (vscroll->is_visible_in_tree()) if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height()); vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height());
handled = true;
}
} break; } break;
case KEY_DOWN: { case KEY_DOWN: {
if (vscroll->is_visible_in_tree()) if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height()); vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height());
handled = true;
}
} break; } break;
case KEY_HOME: { case KEY_HOME: {
if (vscroll->is_visible_in_tree()) if (vscroll->is_visible_in_tree()) {
vscroll->set_value(0); vscroll->set_value(0);
handled = true;
}
} break; } break;
case KEY_END: { case KEY_END: {
if (vscroll->is_visible_in_tree()) if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_max()); vscroll->set_value(vscroll->get_max());
handled = true;
}
} break; } break;
case KEY_INSERT: case KEY_INSERT:
case KEY_C: { case KEY_C: {
if (k->get_command()) { if (k->get_command()) {
selection_copy(); selection_copy();
} else { handled = true;
handled = false;
} }
} break; } break;
default: handled = false;
} }
if (handled) if (handled)