@@ -4162,6 +4162,53 @@ void Graph::handleRenderViewInputs()
41624162 }
41634163}
41644164
4165+
4166+ UiNodePtr Graph::traverseConnection (UiNodePtr node, bool traverseDownstream)
4167+ {
4168+ if (!node)
4169+ {
4170+ return nullptr ;
4171+ }
4172+
4173+ // Get first connected downstream node
4174+ if (traverseDownstream)
4175+ {
4176+ for (UiPinPtr outputPin : node->outputPins )
4177+ {
4178+ // Update downNode info
4179+ for (UiPinPtr connectedPin : outputPin.get ()->getConnections ())
4180+ {
4181+ std::shared_ptr<UiNode> pinNode = connectedPin->_pinNode ;
4182+ if (pinNode)
4183+ {
4184+ return pinNode;
4185+ }
4186+ }
4187+ }
4188+ }
4189+
4190+ // Get first upstream connected node
4191+ else
4192+ {
4193+ for (UiPinPtr inputPin: node->inputPins )
4194+ {
4195+ const std::vector<UiPinPtr>& connections = inputPin->getConnections ();
4196+ std::shared_ptr<UiNode> pinNode = nullptr ;
4197+ if (!connections.empty ())
4198+ {
4199+ UiPinPtr pin = connections[0 ];
4200+ pinNode = pin->_pinNode ;
4201+ if (pinNode)
4202+ {
4203+ return pinNode;
4204+ }
4205+ }
4206+ }
4207+ }
4208+
4209+ return nullptr ;
4210+ }
4211+
41654212void Graph::drawGraph (ImVec2 mousePos)
41664213{
41674214 if (_searchNodeId > 0 )
@@ -4383,7 +4430,47 @@ void Graph::drawGraph(ImVec2 mousePos)
43834430 // or if the shortcut for cut is used
43844431 if (ImGui::IsWindowFocused (ImGuiFocusedFlags_RootWindow))
43854432 {
4386- if (ImGui::IsKeyReleased (ImGuiKey_Delete) || ImGui::IsKeyReleased (ImGuiKey_Backspace) || _isCut)
4433+ bool traverseDownstream = ImGui::IsKeyReleased (ImGuiKey_RightArrow);
4434+ bool traverseUpstream = ImGui::IsKeyReleased (ImGuiKey_LeftArrow);
4435+
4436+ // Traverse connections with arrow keys
4437+ if (traverseDownstream || traverseUpstream)
4438+ {
4439+ UiNodePtr selectedNode = nullptr ;
4440+ if (selectedNodes.size () > 0 )
4441+ {
4442+ for (ed::NodeId id : selectedNodes)
4443+ {
4444+ if (int (id.Get ()) > 0 )
4445+ {
4446+ int pos = findNode (int (id.Get ()));
4447+ if (pos >= 0 )
4448+ {
4449+ selectedNode = _graphNodes[pos];
4450+ break ;
4451+ }
4452+ }
4453+ }
4454+ }
4455+ if (selectedNode && _currUiNode)
4456+ {
4457+ selectedNode = _currUiNode;
4458+ }
4459+
4460+ if (selectedNode)
4461+ {
4462+ UiNodePtr connectedNode = traverseConnection (selectedNode, traverseDownstream);
4463+ if (connectedNode)
4464+ {
4465+ _currUiNode = connectedNode;
4466+ ed::SelectNode (connectedNode->getId ());
4467+ ed::NavigateToSelection ();
4468+ }
4469+
4470+ }
4471+ }
4472+
4473+ else if (ImGui::IsKeyReleased (ImGuiKey_Delete) || ImGui::IsKeyReleased (ImGuiKey_Backspace) || _isCut)
43874474 {
43884475 if (selectedNodes.size () > 0 )
43894476 {
@@ -4436,13 +4523,13 @@ void Graph::drawGraph(ImVec2 mousePos)
44364523 }
44374524
44384525 // Hotkey to frame selected node(s)
4439- if (ImGui::IsKeyReleased (ImGuiKey_F) && !_fileDialogSave.isOpened ())
4526+ else if (ImGui::IsKeyReleased (ImGuiKey_F) && !_fileDialogSave.isOpened ())
44404527 {
44414528 ed::NavigateToSelection ();
44424529 }
44434530
44444531 // Go back up from inside a subgraph
4445- if (ImGui::IsKeyReleased (ImGuiKey_U) && (!ImGui::IsPopupOpen (" add node" )) && (!ImGui::IsPopupOpen (" search" )) && !_fileDialogSave.isOpened ())
4532+ else if (ImGui::IsKeyReleased (ImGuiKey_U) && (!ImGui::IsPopupOpen (" add node" )) && (!ImGui::IsPopupOpen (" search" )) && !_fileDialogSave.isOpened ())
44464533 {
44474534 upNodeGraph ();
44484535 }
0 commit comments