From f3ba89c381aca5079b33ff1cccb2d1561c63e672 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 25 Mar 2025 23:53:40 +0100 Subject: [PATCH] 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. --- editor/editor_node.cpp | 21 +++++++++++++++++++++ editor/scene/canvas_item_editor_plugin.cpp | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3e008c26f6..c03007a086 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -427,6 +427,26 @@ void EditorNode::shortcut_input(const Ref &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 &selection = editor_selection->get_top_selected_node_list(); + + for (Node *E : selection) { + Node *node_with_visibility; + node_with_visibility = Object::cast_to(E); + if (!node_with_visibility || !node_with_visibility->is_inside_tree()) { + node_with_visibility = Object::cast_to(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")); diff --git a/editor/scene/canvas_item_editor_plugin.cpp b/editor/scene/canvas_item_editor_plugin.cpp index bd469880de..31673477f8 100644 --- a/editor/scene/canvas_item_editor_plugin.cpp +++ b/editor/scene/canvas_item_editor_plugin.cpp @@ -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);