I have a problem with contenteditable div. When i want to execute a simple command (like bold or italic) on it, i do the following:
- memorize the div (since it will lose focus after i click on bold button)
- on button click, i refocus the div and execute the bold command
- everything works
Now the problem occurs when i try to do something more difficult. For instance, i want to show a custom dialog with an input field:
- memorize the div
- on button click, a dialog is shown (everything is still ok)
- user focuses an input field on that dialog (and that's where everything breaks)
The problem with this is that as soon as an input element is focused, not only that my contenteditable div loses focus - it also loses the selection and moves the cursor to the beginning as soon as i refocus it.
So my question is: how do i prevent a contenteditable div to lose its selection after i focus on another input element?