Test case: <DIV id="edit" contenteditable>One Two Three Four</DIV>
1.
- Select "Two".
- window.getSelection().anchorNode.nodeValue="One Two Three Four"
- window.getSelection().baseNode.nodeValue="One Two Three Four"
- window.getSelection().extentNode.nodeValue="One Two Three Four"
- window.getSelection().focusNode.nodeValue="One Two Three Four"
- window.getSelection().anchorOffset=4
- window.getSelection().baseOffset=4
- window.getSelection().extentOffset=7
- window.getSelection().focusOffset=7
- With "Two" Selected, run document.execCommand('bold').
- window.getSelection().anchorNode.nodeValue="Two"
- window.getSelection().baseNode.nodeValue="One "
- window.getSelection().extentNode.nodeValue="Two"
- window.getSelection().focusNode.nodeValue="Two"
- window.getSelection().anchorOffset=0
- window.getSelection().baseOffset=4
- window.getSelection().extentOffset=3
- window.getSelection().focusOffset=3
- Select "Three".
- window.getSelection().anchorNode.nodeValue=" Three Four"
- window.getSelection().baseNode.nodeValue=" Three Four"
- window.getSelection().extentNode.nodeValue=" Three Four"
- window.getSelection().focusNode.nodeValue=" Three Four"
- window.getSelection().anchorOffset=1
- window.getSelection().baseOffset=1
- window.getSelection().extentOffset=6
- window.getSelection().focusOffset=6
- Select "Four" and run document.execCommand('bold').
- window.getSelection().anchorNode.nodeValue="Four"
- window.getSelection().baseNode.nodeValue=" Three "
- window.getSelection().extentNode.nodeValue=" Four "
- window.getSelection().focusNode.nodeValue=" Four "
- window.getSelection().anchorOffset=0
- window.getSelection().baseOffset=7
- window.getSelection().extentOffset=4
- window.getSelection().focusOffset=4
- Position cursor immediately after "Four" and press enter. Then Select "Four"
- window.getSelection().anchorNode.nodeValue="Four"
- window.getSelection().baseNode.nodeValue=" Three "
- window.getSelection().extentNode.nodeValue=" Four "
- window.getSelection().focusNode.nodeValue=" Four "
- window.getSelection().anchorOffset=0
- window.getSelection().baseOffset=7
- window.getSelection().extentOffset=4
- window.getSelection().focusOffset=4
3 comments:
I realize this probably isn't useful for anyone, but I wanted to write it down somewhere for me.
Actually, I'm working with getSelection issue and I did find it useful, so thank you.
Very useful. Thanks for posting your research.
Post a Comment