Add H keyboard shortcut to toggle node visibility in the 2D and 3D editors

This can be used to quickly toggle visibility of all selected nodes
in the editor.

Note that the default shortcut won't work when the Scene tree dock is
focused, as incremental search takes priority over the shortcut.

This changes the Show Helpers shortcut in the 2D editor to Shift + H
by default to avoid conflicts with this new shortcut.
This commit is contained in:
Hugo Locurcio 2025-03-25 23:53:40 +01:00
parent 4d4f7291ed
commit f3ba89c381
No known key found for this signature in database
GPG key ID: 46ACE49F61685096
2 changed files with 22 additions and 1 deletions

View file

@ -427,6 +427,26 @@ void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) {
_open_command_palette();
} else if (ED_IS_SHORTCUT("editor/toggle_last_opened_bottom_panel", p_event)) {
bottom_panel->toggle_last_opened_bottom_panel();
} else if (ED_IS_SHORTCUT("editor/toggle_selected_nodes_visibility", p_event)) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Toggle Selected Node(s) Visibility"));
const List<Node *> &selection = editor_selection->get_top_selected_node_list();
for (Node *E : selection) {
Node *node_with_visibility;
node_with_visibility = Object::cast_to<CanvasItem>(E);
if (!node_with_visibility || !node_with_visibility->is_inside_tree()) {
node_with_visibility = Object::cast_to<Node3D>(E);
if (!node_with_visibility || !node_with_visibility->is_inside_tree()) {
continue;
}
}
undo_redo->add_do_method(node_with_visibility, "set_visible", !node_with_visibility->get("visible"));
undo_redo->add_undo_method(node_with_visibility, "set_visible", node_with_visibility->get("visible"));
}
undo_redo->commit_action();
} else {
is_handled = false;
}
@ -8259,6 +8279,7 @@ EditorNode::EditorNode() {
ED_SHORTCUT("editor/unlock_selected_nodes", TTRC("Unlock Selected Node(s)"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::L);
ED_SHORTCUT("editor/group_selected_nodes", TTRC("Group Selected Node(s)"), KeyModifierMask::CMD_OR_CTRL | Key::G);
ED_SHORTCUT("editor/ungroup_selected_nodes", TTRC("Ungroup Selected Node(s)"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::G);
ED_SHORTCUT("editor/toggle_selected_nodes_visibility", TTRC("Toggle Selected Node(s) Visibility"), Key::H);
FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename"));

View file

@ -5936,7 +5936,7 @@ CanvasItemEditor::CanvasItemEditor() {
grid_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/toggle_grid", TTRC("Toggle Grid"), KeyModifierMask::CMD_OR_CTRL | Key::APOSTROPHE));
p->add_submenu_node_item(TTRC("Grid"), grid_menu);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTRC("Show Helpers"), Key::H), SHOW_HELPERS);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTRC("Show Helpers"), KeyModifierMask::SHIFT | Key::H), SHOW_HELPERS);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTRC("Show Rulers")), SHOW_RULERS);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTRC("Show Guides"), Key::Y), SHOW_GUIDES);
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_origin", TTRC("Show Origin")), SHOW_ORIGIN);