Header removals wait for the code editor to be left: autosave saves with drop=false, so follow_header adds and renames from the header but keeps a port or setting whose parameter is gone, and leaving the editor (blur or closing the panel) saves once more with removals; source saves of a flow run one at a time
This commit is contained in:
@@ -1837,7 +1837,7 @@ def _signature_gap(
|
||||
)
|
||||
|
||||
|
||||
def follow_header(node: NodeDef, code: str) -> NodeDef:
|
||||
def follow_header(node: NodeDef, code: str, drop: bool = True) -> NodeDef:
|
||||
"""The node with its input ports and settings read off ``def process(...)``.
|
||||
|
||||
The inverse of the canvas's scaffold, which writes the input ports first,
|
||||
@@ -1845,7 +1845,9 @@ def follow_header(node: NodeDef, code: str) -> NodeDef:
|
||||
keeps its kind. A new one is a setting when it has a default, which becomes
|
||||
its value, or when it follows a setting, and an input port otherwise. One
|
||||
name swapped for one other is a rename, so the port keeps its message and
|
||||
the setting its value. A declared name the header no longer has is dropped.
|
||||
the setting its value. A declared name the header no longer has is dropped,
|
||||
unless ``drop`` is false: code saved while it is still being typed keeps
|
||||
those, so a pause mid-edit does not cost a port its message.
|
||||
|
||||
A header this cannot read for certain leaves the node as it is: a syntax
|
||||
error, no top-level ``def process``, a decorator, ``*args``, ``**kwargs``,
|
||||
@@ -1907,6 +1909,13 @@ def follow_header(node: NodeDef, code: str) -> NodeDef:
|
||||
after_setting = True
|
||||
else:
|
||||
requires.append(MessageSpec(port=name))
|
||||
if not drop:
|
||||
kept = set(gone) - set(renamed.values())
|
||||
# Where they were, so that typing the name back changes nothing.
|
||||
for index, spec in enumerate(node.requires):
|
||||
if spec.port in kept:
|
||||
requires.insert(index, spec)
|
||||
params |= {key: settings[key] for key in kept if key in settings}
|
||||
# Ports the header cannot name, such as a row not named yet, stay.
|
||||
requires += [spec for spec in node.requires if not written(spec.port)]
|
||||
return node.model_copy(update={"requires": requires, "params": params})
|
||||
|
||||
Reference in New Issue
Block a user