I've seen a lot of code snippets detailing how to get and set the caret position within a contenteditable div but I cannot get it to work in my case:
I am using a WYSIWYG text editor (textAngular). I have included functionality for the user to insert a cross-reference at the cursor position. They click a button, which opens up a dialog box for them to make selections from, which in turn will insert a html node at the current cursor position.
The location of the cursor may be within child nodes within the div such as p tags and/or other formatting tags.
My issue is that the current cursor position is lost when the dialog gains focus. I have tried storing the caret position (node and offset) in memory before opening the dialog but whatever I try the caret position always returns to the start of the div. I've tried all the code snippets I can find on stackoverflow but none of them work. I assume I am missing something.