Extract to function

It is called “Collapse to Function” and already exists, exactly like you describe; right click selected nodes and the collapse option is there…

1 Like