Skip to content

Sketch2: add line#72270

Open
bencodeorg wants to merge 26 commits intostagingfrom
ben/sketch2-line-as-edge
Open

Sketch2: add line#72270
bencodeorg wants to merge 26 commits intostagingfrom
ben/sketch2-line-as-edge

Conversation

@bencodeorg
Copy link
Copy Markdown
Contributor

@bencodeorg bencodeorg commented Apr 21, 2026

Implements a line as an edge that connects two "ghost nodes".

As an alternative, I went down the path of implementing this as a "custom node" (very rough): https://github.com/code-dot-org/code-dot-org/compare/ben/sketch2-line

I think implementing it as an edge makes sense longer term because we'll be able tap into the built-in goodness that React Flow includes for "lines" as part of its edge implementation.

Their docs (linked below) also mention the idea ("What about an “edge” not connected to any nodes at all?") of an edge with no nodes (ie, what we're trying to do), so that seems like a reasonable standard approach.

line.mov

Links

Testing story

Tested manually (see video above).

Follow-up work

  • Hide handles unless focused (should be able to tap into some of the work done to do this on other node types).
  • Center drag handles on edges of the line. This was trickier than I expected and I wanted to get a V0 out, so punted for now.
  • Add support for arrow heads, colors, thicknesses, etc.
  • Would be nice to have a drag target on the center of the edge, although that might be tricky.

@bencodeorg bencodeorg requested a review from a team April 23, 2026 20:13
Copy link
Copy Markdown
Contributor

@molly-moen molly-moen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really cool! Couple small comments, not blocking.

);
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll probably want to do some refactoring of this file to split it up a bit, but that should be a follow up. I think we'll hit some (hopefully easily resolvable) conflicts with my open pr: https://github.com/code-dot-org/code-dot-org/pull/72285/changes#diff-ace9cf822f2f2ed4aa8449d365844fc5133b457594967265eb153fd690d0574e

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 agreed, it's getting hefty.


// Arrow keys on a focused line edge move the whole line by moving
// both line-anchor nodes together.
if (!readOnly && focusedEdgeId) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like there's a bit of duplicate logic between the two if statements, can we extract anything out here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, let me see if I can dedupe this a bit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deduped here: 1f89e01

SketchlabReactFlowNode,
} from '@cdo/apps/lab2/types';

export function canCreateConnection(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth adding a comment here? I think it's checking that you aren't connecting a 'line' to an existing node, is that right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry missed this, simplified and added a comment here: ca2f28f

Yeah hopefully clearer now, but it's just there to prevent other nodes from connecting to a (ghost) line anchor.

announce(`Edge created to ${getNodeLabel(targetNode)}.`);
if (connectionRejected) {
announce(
'Connection not created. Line endpoints may only have one edge.'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if I got this message as a user I would be confused. What does it mean in terms of what the user sees on the screen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good callout, I had questions about this as well. This is for the case where you're in the "connect mode" via keyboard nav, and try to connect to one of the "nodes" of a line.

I just tested it with a screenreader, and it did correctly reject a connection. We might want to do something else in the future (make line nodes non-tabbable when in connect mode?), but for now I can add a clearer message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated message here: f1e0120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants