Hello, How would one go about getting the absolute position of a mark when the mouse is not focused or selected on that tag? Is this possible with Prosemirror?
For more context as to the specific use case of this… I have a custom schema that tacks on a guid as well as some other attributes to the mark. These are then rendered in a component that is separate from the editor. From this rendered component, I would like to be able to delete/update the marks and have that be reflected in the schema presented by the editor, but I would need to know their absolute positions in the editor so I know which parts of the schema need to be updated. I would hope that one of the ways listed below would be a valid way to go about getting the absolute position of a given mark, but I’m not sure if this is something Prosemirror is capable of.
Way 1:
const mark = document.getElementById(this.guid);
// get the to and from positions off of the constant mark.
Way 2: Within the schema, storing the absolute position on a data attribute. (I could save this whenever a mark is added since I am toggling marks on selected ranges, but that wouldn’t account for copying/pasting that mark around the document or editing text around the mark that would ultimately change it’s absolute position)
get schema(): MarkSpec {
return {
attrs: {
attributes: {}
},
toDOM: (node: any) => [
'mark',
{
'data-value': JSON.parse(node.attrs.attributes).value,
id: JSON.parse(node.attrs.attributes).guid,
from: // Somehow get the from selection,
to: // Somehow get the to selection
}
],
parseDOM: [
{
...
...
...
}
]
};
}