normalizeBoundaries

startContainer and endContainer are the same TextNode

This is a test sentence
This is a test sentence

startContainer and endContainer are a different TextNode

This is a
test sentence
This is a
test sentence

startContainer and endContainer are an ElementNode

This is a real test sentence
This is a real test sentence

startContainer and endContainer are an ElementNode in a different div

aaa bbb cccc
xxx yyy zzz
aaa bbb cccc
xxx yyy zzz

startContainer is an ElementNode but endContainer is a TextNode

aaa bbb cccc
xxx yyy zzz
aaa bbb cccc
xxx yyy zzz

range.startContainer と range.endContainer は二通りのケースがあり、
これが話をややこしくする。

(ケース1) startContainer と endContainer がText Nodeの場合、
startOffset と endOffset は文字の位置を示す。

(ケース2) startContainer と endContainer がElementの場合、
startOffset と endOffset は、childNodes の Indexを示す。

以下の4つの組み合わせが考えられる。

[1] startContainer=TextNode, endContainer=TextNode
[2] startContainer=TextNode, endContainer=ElementNode
[3] startContainer=ElementNode, endContainer=TextNode
[4] startContainer=ElementNode, endContainer=ElementNode

最終的には、[4]の形にするわけなので、最初から[4]の場合なにもしない。

さて、[1]=>[4]は変換が可能だが、[2]=>[4]、[3]=>[4]、は難しい。
それは、[2]や[3]にあるTextNodeをSplitするのが難しいからだ。

そこで、まず、すべて[1]に変換して、そこから[4]へもっていく。