git.lucas.co / hou-control
git clone https://git.lucas.co/hou-control.git

commitfac7d8decf60652f86f12661c963ef287e2584c5
parent32e521bb2e
authorLucas Galante <[email protected]>
date2026-04-17 09:48
hc: ensure select next/prev component first completes the current node component selection

 python3.11libs/hc/hcnetworkeditor.py | 45 ++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/python3.11libs/hc/hcnetworkeditor.py b/python3.11libs/hc/hcnetworkeditor.py
index a0ad466..be293c7 100644
--- a/python3.11libs/hc/hcnetworkeditor.py
+++ b/python3.11libs/hc/hcnetworkeditor.py
@@ -338,24 +338,39 @@ class HCNetworkEditor(HCPathTab):
             return (cx, -cy)
 
         selected_set = set(self.hou_tab.pwd().selectedChildren())
+        current = self.hou_tab.currentNode()
         ref_comp = None
         
-        # Only try to find a reference component if we have a selection
-        if selected_set:
-            current = self.hou_tab.currentNode()
-            if current is not None:
-                for comp in components:
-                    if current in comp:
-                        ref_comp = comp
-                        break
-            if ref_comp is None:
-                for comp in components:
-                    if any(n in selected_set for n in comp):
-                        ref_comp = comp
-                        break
-
+        # 1. Determine if we are currently "inside" a component
+        if current is not None:
+            for comp in components:
+                if current in comp:
+                    # Check if this component is already fully selected
+                    comp_set = set(comp)
+                    if not comp_set.issubset(selected_set):
+                        # Not fully selected! Our target is to complete this component.
+                        target = comp
+                        for node in self.hou_tab.pwd().children():
+                            node.setSelected(node in target)
+                        self._frameSelectionInView()
+                        self.updateCurrentNodeOverlay()
+                        return
+                    
+                    # Component is already fully selected, use it as reference for navigation
+                    ref_comp = comp
+                    break
+        
+        # 2. If no current node, or current node's component was already fully selected,
+        # but there is other selection, find the reference component from that.
+        if ref_comp is None and selected_set:
+            for comp in components:
+                if any(n in selected_set for n in comp):
+                    ref_comp = comp
+                    break
+
+        # 3. Handle Navigation
         if ref_comp is None:
-            # Sort all components and pick the top-left one (first in sorted list)
+            # Fallback: Sort all components and pick the top-left one
             components.sort(key=sort_key)
             target = components[0]
         else: