Skip to content
Discussion options

You must be logged in to vote

I've not tested this, but you could do something like the below to get the bounding box of the second-most parent element for each node in the tree, and then use that to position to absolutely position a floating menu.

const anchorNode = $getSelection().anchorNode;

const secondLevelParentNode = $findMatchingParent(anchorNode, node => $getDepth(node) === 1)

const matchingElementForSecondLevelParentNode = editor.getElementByKey(secondLevelParentNode.getKey())

const {x, y} = matchingElementForSecondLevelParentNode.getBoundingClientRect()

You could then use registerUpdateListener to recalculate the positions, any time there is an update to editor state.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by thegreatercurve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants