You need to be logged in to post in the forums. If you do not have an account, please sign up first.
Updating selection in designMode
Hi,I'm playing with selections in "designMode" and for some reason I'm unable to update the selection after inserting an element.
I reckon the following code should do the trick:
var range=self.iframe.contentWindow.getSelection().getRangeAt(0); range.deleteContents(); range.insertNode(element); range.selectNode(element);
With Firefox 14 this works like a charm, but Opera just leaves a blinking cursor at the first position of the original selection
Another trick I tried was to replace the "selectNode" with the following:
var snode=range.startContainer.nextSibling; var enode=range.startContainer.nextSibling.nextSibling; var range=self.iframe.contentWindow.getSelection().getRangeAt(0); range.setStart(snode, 0); range.setEnd(enode, 0);
And again with no success.
I've tested the code with Opera 12.01 and 12.50 (beta) both under Linux and more or less with the same outcome.
Suggestions are welcome!
Cheers,
Verty
Hi again,
It seems I found the solution for this problem. Apparently you will need to replace the range, so removing the old one(s) and adding the new.
In other words you will need to add the following extra lines (at the end of the examples given above):
Where selection is self.iframe.contentWindow.getSelection().
Seem to work nicely with Opera 12 so problem solved!
I am still considering reporting this as a bug though since both Chrome and Firefox work without this addition. Then again it's nowhere mentioned specifically that setStart / selectNode update the selection.
Cheers,
Verty
It seems I found the solution for this problem. Apparently you will need to replace the range, so removing the old one(s) and adding the new.
In other words you will need to add the following extra lines (at the end of the examples given above):
selection.removeAllRanges(); selection.addRange(range);
Where selection is self.iframe.contentWindow.getSelection().
Seem to work nicely with Opera 12 so problem solved!
I am still considering reporting this as a bug though since both Chrome and Firefox work without this addition. Then again it's nowhere mentioned specifically that setStart / selectNode update the selection.
Cheers,
Verty