Hello,
I’m having some issues with positions.
I have the following:
<section>
<!-- .... -->
<article>
<p>Flex child 12</p>
<!-- I'm moving my mouse here -->
</article>
<!-- ... -->
</section>
which, in practice, correspond to the following:
and I have the following code:
const outlineNodePlugin = new Plugin({
props: {
handleDOMEvents: {
mouseover(view, event) {
const { nodeHover } = storeToRefs(storeEditorEvent)
// We clicked in the editor, retrieve the PM document position
let pos = view.posAtDOM(event.target)
console.log('===>>> HOVER1: ', pos)
// Compute the new lineage from that pos
const lineage = []
view.state.doc.nodesBetween(pos, pos, (node, _pos) => {
console.log('===>>> HOVER LOOP: ', _pos, node.type.name, node.isText)
if (!node.isText) {
lineage.push(_pos)
}
})
// Get closest pos in the lineage tree
if (lineage.length > 0) {
pos = lineage.reduce(
(prev, curr) => Math.abs(curr - pos) < Math.abs(prev - pos) ? curr : prev
)
}
// Check which node do we have at this pos
const node = view.state.doc.nodeAt(pos)
console.log('===>>> HOVER2: ', pos, node?.type.name)
nodeHover.value = {
node: node,
pos: pos
}
},
When I’m moving my cursor as in the screenshot above (so outside of the <p>
tag and within the <article>
tag I don’t understand why I’m getting the pos
of the <p>
(333) node and not of the flexItem (<article>
) node (332)?
Then I have also an issue with the nodesBetween
part of the code above when a custom node (Image) view is involved, the template of that view looks like:
<template>
<node-view-wrapper :as="as" :class="wrapper_cls">
<img draggable data-drag-handle
ref="img"
class="rounded-lg"
:src="node.attrs.src"
:data-objectid="node.attrs['data-objectid']"
:width="width_attr"
:height="height_attr"
:class="[img_cls, extra_cls_img, bg_color_cls]"
/>
<resizeNode v-if="editable" :editor="editor" :selected="selected" :node="img" @resize="(size) => updateAttributes(size)" v-show="selected && img" />
</node-view-wrapper>
</template>
as of:
the Image node isn’t returned by nodesBetween
, it stops at the parent node (flexItem) … any idea?
Thanks!