Skip to content

Commit 375dc7b

Browse files
feat: show some block for context when opening action menu (#191)
Previously it was shown over the top left, which obscured useful context. I considered positioning it below the block but it can be a long way down in some cases. That can feel unexpected and makes it more likely that the menu is repositioned to keep it on screen. Mentioned on #184 (comment) This is a less arbitrary version of the offset I had in "Demo A" (that just used 50px which looked fine for zelos styling but not great in geras).
1 parent 19fed27 commit 375dc7b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/navigation.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,14 +1406,27 @@ function fakeEventForNode(node: Blockly.ASTNode): PointerEvent {
14061406
// Get the location of the top-left corner of the block in
14071407
// screen coordinates.
14081408
const block = node.getLocation() as Blockly.BlockSvg;
1409-
const coords = Blockly.utils.svgMath.wsToScreenCoordinates(
1409+
const blockCoords = Blockly.utils.svgMath.wsToScreenCoordinates(
14101410
block.workspace,
14111411
block.getRelativeToSurfaceXY(),
14121412
);
14131413

1414+
// Prefer a y position below the first field in the block.
1415+
const fieldBoundingClientRect = block.inputList
1416+
.filter((input) => input.isVisible())
1417+
.flatMap((input) => input.fieldRow)
1418+
.filter((f) => f.isVisible())[0]
1419+
?.getSvgRoot()
1420+
?.getBoundingClientRect();
1421+
1422+
const clientY =
1423+
fieldBoundingClientRect && fieldBoundingClientRect.height
1424+
? fieldBoundingClientRect.y + fieldBoundingClientRect.height
1425+
: blockCoords.y + block.height;
1426+
14141427
// Create a fake event for the action menu code to work from.
14151428
return new PointerEvent('pointerdown', {
1416-
clientX: coords.x,
1417-
clientY: coords.y,
1429+
clientX: blockCoords.x + 5,
1430+
clientY: clientY + 5,
14181431
});
14191432
}

0 commit comments

Comments
 (0)