| 108 | |
| 109 | var range = selection.getRanges()[ 0 ]; |
| 110 | var selectionStart = range.startContainer; |
| 111 | var selectionEnd = range.endContainer; |
| 112 | var parent; |
| 113 | |
| 114 | // Check if all elements children are included in the selection. |
| 115 | while ( ( parent = selectionStart.getParent() ) && parent.$ != selectedElement ) |
| 116 | selectionStart = parent; |
| 117 | |
| 118 | while ( ( parent = selectionEnd.getParent() ) && parent.$ != selectedElement ) |
| 119 | selectionEnd = parent; |
| 120 | |
| 121 | // TODO should we skip border text nodes here ? |
| 122 | if ( selectionStart.getIndex() > 0 || selectionStart.getIndex() + 1 < selectedElement.getChildCount() ) |
| 123 | return null; |
| 124 | |
| 125 | // Enlarge selection to all elements with only one child (but stop on elements we want). |