Skip to content

Commit

Permalink
Fix recursive Tree expand/collapse shortcuts not working
Browse files Browse the repository at this point in the history
This also moves them to use Shift instead of Alt, as was already
done for mouse interactions.

Shortcuts in Tree were also made non-exact matches so they still
work if modifiers are held. This is important for up/down
shortcuts, especially once support for selecting with
Shift + up/down is implemented.
  • Loading branch information
Calinou committed Feb 13, 2024
1 parent 9050ee1 commit 6de0eca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion doc/classes/Tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
This controls the drop sections, i.e. the decision and drawing of possible drop locations based on the mouse position.
</member>
<member name="enable_recursive_folding" type="bool" setter="set_enable_recursive_folding" getter="is_recursive_folding_enabled" default="true">
If [code]true[/code], recursive folding is enabled for this [Tree]. Holding down Shift while clicking the fold arrow collapses or uncollapses the [TreeItem] and all its descendants.
If [code]true[/code], recursive folding is enabled for this [Tree]. Holding down [kbd]Shift[/kbd] while clicking the fold arrow or using [code]ui_right[/code]/[code]ui_left[/code] shortcuts collapses or uncollapses the [TreeItem] and all its descendants.
</member>
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" overrides="Control" enum="Control.FocusMode" default="2" />
<member name="hide_folding" type="bool" setter="set_hide_folding" getter="is_folding_hidden" default="false">
Expand Down
34 changes: 12 additions & 22 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3394,25 +3394,20 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;

bool is_command = k.is_valid() && k->is_command_or_control_pressed();
if (p_event->is_action("ui_right", true) && p_event->is_pressed()) {
if (p_event->is_action("ui_right") && p_event->is_pressed()) {
if (!cursor_can_exit_tree) {
accept_event();
}

if (!selected_item || select_mode == SELECT_ROW || selected_col > (columns.size() - 1)) {
return;
}
if (k.is_valid() && k->is_alt_pressed()) {
selected_item->set_collapsed(false);
TreeItem *next = selected_item->get_first_child();
while (next && next != selected_item->next) {
next->set_collapsed(false);
next = next->get_next_visible();
}
if (k.is_valid() && k->is_shift_pressed()) {
selected_item->set_collapsed_recursive(false);
} else {
_go_right();
}
} else if (p_event->is_action("ui_left", true) && p_event->is_pressed()) {
} else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
if (!cursor_can_exit_tree) {
accept_event();
}
Expand All @@ -3421,32 +3416,27 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
return;
}

if (k.is_valid() && k->is_alt_pressed()) {
selected_item->set_collapsed(true);
TreeItem *next = selected_item->get_first_child();
while (next && next != selected_item->next) {
next->set_collapsed(true);
next = next->get_next_visible();
}
if (k.is_valid() && k->is_shift_pressed()) {
selected_item->set_collapsed_recursive(true);
} else {
_go_left();
}

} else if (p_event->is_action("ui_up", true) && p_event->is_pressed() && !is_command) {
} else if (p_event->is_action("ui_up") && p_event->is_pressed() && !is_command) {
if (!cursor_can_exit_tree) {
accept_event();
}

_go_up();

} else if (p_event->is_action("ui_down", true) && p_event->is_pressed() && !is_command) {
} else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) {
if (!cursor_can_exit_tree) {
accept_event();
}

_go_down();

} else if (p_event->is_action("ui_page_down", true) && p_event->is_pressed()) {
} else if (p_event->is_action("ui_page_down") && p_event->is_pressed()) {
if (!cursor_can_exit_tree) {
accept_event();
}
Expand Down Expand Up @@ -3484,7 +3474,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
}

ensure_cursor_is_visible();
} else if (p_event->is_action("ui_page_up", true) && p_event->is_pressed()) {
} else if (p_event->is_action("ui_page_up") && p_event->is_pressed()) {
if (!cursor_can_exit_tree) {
accept_event();
}
Expand Down Expand Up @@ -3521,7 +3511,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
prev->select(selected_col);
}
ensure_cursor_is_visible();
} else if (p_event->is_action("ui_accept", true) && p_event->is_pressed()) {
} else if (p_event->is_action("ui_accept") && p_event->is_pressed()) {
if (selected_item) {
//bring up editor if possible
if (!edit_selected()) {
Expand All @@ -3530,7 +3520,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
}
}
accept_event();
} else if (p_event->is_action("ui_select", true) && p_event->is_pressed()) {
} else if (p_event->is_action("ui_select") && p_event->is_pressed()) {
if (select_mode == SELECT_MULTI) {
if (!selected_item) {
return;
Expand Down

0 comments on commit 6de0eca

Please sign in to comment.