+ if (commonNode.nodeType == Node.TEXT_NODE) {
+ commonNode = commonNode.parentNode;
+ }
+ let node = range.startContainer;
+ if (node.nodeType == Node.TEXT_NODE) {
+ node = node.parentNode;
+ }
+ if (node != commonNode) {
+ window.alert("Zły obszar.");
+ return false;
+ }
+
+ let end;
+ if (range.endContainer.nodeType == Node.TEXT_NODE) {
+ end = range.endContainer.splitText(range.endOffset);
+ } else {
+ end = document.createTextNode('');
+ let cont = $(range.endContainer).contents();
+ if (range.endOffset < cont.length) {
+ range.endContainer.insertBefore(end, cont[range.endOffset])
+ } else {
+ range.endContainer.append(end);
+ }
+ }
+
+ let current;
+ if (range.startContainer.nodeType == Node.TEXT_NODE) {
+ current = range.startContainer.splitText(range.startOffset);
+ } else {
+ current = document.createTextNode('');
+ let cont = $(range.startContainer).contents();
+ if (range.startOffset < cont.length) {
+ range.startContainer.insertBefore(current, cont[range.startOffset])
+ } else {
+ startNode.append(current);
+ }
+ }
+
+ // We will construct a HTML element with the range selected.
+ let div = $("<span x-pass-thru='true'>");
+ while (current != end) {
+ n = current.nextSibling;
+ $(current).appendTo(div);
+ current = n;
+ }