Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node being selected after deleting node or connection #11902

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Next Next Release
# Next Release

#### Enso Language & Runtime

- [Intersection types & type checks][11600]
- A constructor or type definition with a single inline argument definition was
previously allowed to use spaces in the argument definition without
parentheses. [This is now a syntax error.][11856]
- [Fixed nodes being selected after deleting other nodes or connections.][11902]

[11600]: https://github.com/enso-org/enso/pull/11600
[11856]: https://github.com/enso-org/enso/pull/11856

# Next Release
# Enso 2024.4

#### Enso IDE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ function selectNode() {
}

function handleWidgetUpdates(update: WidgetUpdate) {
selectNode()
if (update.directInteraction) {
selectNode()
}
const edit = update.edit ?? graph.startEdit()
if (update.portUpdate) {
const { origin } = update.portUpdate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interaction.setWhen(() => graph.mouseEditedEdge != null, editingEdge)

function disconnectEdge(target: PortId) {
graph.edit((edit) => {
if (!graph.updatePortValue(edit, target, undefined)) {
if (!graph.updatePortValue(edit, target, undefined, false)) {
if (isAstId(target)) {
console.warn(`Failed to disconnect edge from port ${target}, falling back to direct edit.`)
edit.replaceValue(target, Ast.Wildcard.new(edit))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function handleArgUpdate(update: WidgetUpdate): boolean {
console.error('Tried to set metadata on arg placeholder. This is not implemented yet!')
return false
}
const { value, origin } = update.portUpdate
const {
portUpdate: { value, origin },
directInteraction,
} = update

const edit = update.edit ?? graph.startEdit()
// Find the updated argument by matching origin port/expression with the appropriate argument.
// We are interested only in updates at the top level of the argument AST. Updates from nested
Expand All @@ -107,7 +111,7 @@ function handleArgUpdate(update: WidgetUpdate): boolean {
edit
.getVersion(argApp.appTree)
.updateValue((oldAppTree) => Ast.App.new(edit, oldAppTree, name, newArg))
props.onUpdate({ edit })
props.onUpdate({ edit, directInteraction })
return true
} else if (value == null && argApp?.argument instanceof ArgumentAst) {
/* Case: Removing existing argument. */
Expand Down Expand Up @@ -148,6 +152,7 @@ function handleArgUpdate(update: WidgetUpdate): boolean {
value: func,
origin: argApp.appTree.id,
},
directInteraction,
})
return true
} else if (argApp.appTree instanceof Ast.OprApp) {
Expand All @@ -162,6 +167,7 @@ function handleArgUpdate(update: WidgetUpdate): boolean {
value: lhs,
origin: argApp.appTree.id,
},
directInteraction,
})
}
return true
Expand All @@ -184,7 +190,7 @@ function handleArgUpdate(update: WidgetUpdate): boolean {
} else {
appTree.update((appTree) => appTree.function.take())
}
props.onUpdate({ edit })
props.onUpdate({ edit, directInteraction })
return true
} else {
// Process an argument to the right of the removed argument.
Expand Down
5 changes: 5 additions & 0 deletions app/gui/src/project-view/providers/widgetRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export interface WidgetUpdate {
| { value: Ast.Owned<Ast.MutableExpression> | string | undefined }
| { metadataKey: string; metadata: unknown }
)
/**
* Set to true if the updated is caused by direct interaction with the origin widget - a usual case.
* An example if _nondirect_ interaction is an update of a port connected to a removed node).
*/
directInteraction: boolean
}

/**
Expand Down
11 changes: 9 additions & 2 deletions app/gui/src/project-view/stores/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export const [provideGraphStore, useGraphStore] = createContextStore(
// Skip ports on already deleted nodes.
if (nodeId && deletedNodes.has(nodeId)) continue

updatePortValue(edit, usage, undefined)
updatePortValue(edit, usage, undefined, false)
}
const outerAst = edit.getVersion(node.outerAst)
if (outerAst.isStatement()) Ast.deleteFromParentBlock(outerAst)
Expand Down Expand Up @@ -577,17 +577,24 @@ export const [provideGraphStore, useGraphStore] = createContextStore(
* Emit a value update to a port view under specific ID. Returns `true` if the port view is
* registered and the update was emitted, or `false` otherwise.
*
* The properties are analogous to {@link WidgetUpdate fields}.
*
* NOTE: If this returns `true,` The update handlers called `graph.commitEdit` on their own.
* Therefore, the passed in `edit` should not be modified afterward, as it is already committed.
*/
function updatePortValue(
edit: MutableModule,
id: PortId,
value: Ast.Owned<Ast.MutableExpression> | undefined,
directInteraction: boolean = true,
): boolean {
const update = getPortPrimaryInstance(id)?.onUpdate
if (!update) return false
update({ edit, portUpdate: { value, origin: id } })
update({
edit,
portUpdate: { value, origin: id },
directInteraction,
})
return true
}

Expand Down
Loading