@mocanvas/editor · function

getNearestAdjacentShape

declare function getNearestAdjacentShape(editor: Editor, shape: ShapeRef, direction: TLAdjacentDirection): UnknownShape | undefined

The shape a person means when they press an arrow key from shape.

Candidates are the shapes on the current page that lie in direction — their centre must be past this shape's edge — and that overlap it on the other axis, so pressing right from a card in a row of cards moves along the row rather than diagonally to something far away.

SEMANTICS-ASSUMED: the parameter order is (shape, direction), and the overlap test uses the adjacentShapeMargin option as a tolerance so shapes laid out a pixel or two out of line still count as being in the same row. Ties are broken by distance between centres, so the *nearest* aligned shape wins rather than the one that happens to sort first.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.