I’m new to ProseMirror, started a couple days ago (but getting the hang of it pretty quickly).
I’m working on a floating menu and I want to make it “smart.” For instance, detect if the caret location is on an empty newline (or an empty node? Not 100% sure of the terminology just yet).
Or if it’s directly below an H2 heading. Or if the line before ends with a “?” (even if the line is in the paragraph above).
The menu part is easy.
But I can’t seem to find how to detect caret position to determine if it is on a new empty node/newline. Or at the end of t
I’ve tried things like $from.nodeBefore.textContent
.
I’ve managed to detect when at the end of a paragraph (at least it seems to be working). I do this:
const { $from, $to } = editor.state.selection
const isAtEnd = ($from.parent.type.isTextblock && $from.parentOffset === $from.parent.content.size) || false
But I could be mistaken, or there’s an easier way?
Forgive me if these are newbie/naive questions. I promise I’ll pick up on things very fast once I know.
Thank you in advance.