How to detect if there is a white space at the right of the cursor in real time when user is typing

I was trying to test if there is a white space at the right of the cursor in real time while the user is typing by using slice()

const prevNode = doc.nodeAt(pos - 1); // this always gives the text node being actually edited
const slice = prevNode.slice(pos, pos + 1);

but i’m getting the error Uncaught RangeError: Position out of range.

Is there a way to achieve?

textBetween is probably the easiest way do to this.

1 Like