|
@@ -122,16 +122,20 @@ this.singlefile.ui = this.singlefile.ui || (() => {
|
|
|
if (range && range.commonAncestorContainer) {
|
|
if (range && range.commonAncestorContainer) {
|
|
|
const treeWalker = document.createTreeWalker(range.commonAncestorContainer);
|
|
const treeWalker = document.createTreeWalker(range.commonAncestorContainer);
|
|
|
const ancestorElement = range.commonAncestorContainer != Node.ELEMENT_NODE ? range.commonAncestorContainer.parentElement : range.commonAncestorContainer;
|
|
const ancestorElement = range.commonAncestorContainer != Node.ELEMENT_NODE ? range.commonAncestorContainer.parentElement : range.commonAncestorContainer;
|
|
|
- while (treeWalker.nextNode() && treeWalker.currentNode != range.endContainer) {
|
|
|
|
|
- if (treeWalker.currentNode == range.startContainer) {
|
|
|
|
|
|
|
+ if (treeWalker.currentNode == range.endContainer) {
|
|
|
|
|
+ selectionFound = true;
|
|
|
|
|
+ markSelectedNode(treeWalker.currentNode);
|
|
|
|
|
+ }
|
|
|
|
|
+ while (treeWalker.currentNode != range.endContainer) {
|
|
|
|
|
+ if (treeWalker.currentNode == range.startContainer || treeWalker.currentNode == range.endContainer) {
|
|
|
selectionFound = true;
|
|
selectionFound = true;
|
|
|
}
|
|
}
|
|
|
if (selectionFound) {
|
|
if (selectionFound) {
|
|
|
- const element = treeWalker.currentNode.nodeType == Node.ELEMENT_NODE ? treeWalker.currentNode : treeWalker.currentNode.parentElement;
|
|
|
|
|
- element.setAttribute(SingleFile.SELECTED_CONTENT_ATTRIBUTE_NAME, "");
|
|
|
|
|
|
|
+ markSelectedNode(treeWalker.currentNode);
|
|
|
}
|
|
}
|
|
|
|
|
+ treeWalker.nextNode();
|
|
|
}
|
|
}
|
|
|
- if (selectionFound || treeWalker.currentNode == range.endContainer) {
|
|
|
|
|
|
|
+ if (selectionFound) {
|
|
|
ancestorElement.setAttribute(SingleFile.SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME, "");
|
|
ancestorElement.setAttribute(SingleFile.SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME, "");
|
|
|
contentSelected = true;
|
|
contentSelected = true;
|
|
|
}
|
|
}
|
|
@@ -140,6 +144,11 @@ this.singlefile.ui = this.singlefile.ui || (() => {
|
|
|
return contentSelected;
|
|
return contentSelected;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function markSelectedNode(node) {
|
|
|
|
|
+ const element = node.nodeType == Node.ELEMENT_NODE ? node : node.parentElement;
|
|
|
|
|
+ element.setAttribute(SingleFile.SELECTED_CONTENT_ATTRIBUTE_NAME, "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function markSelectedArea(selectedAreaElement) {
|
|
function markSelectedArea(selectedAreaElement) {
|
|
|
selectedAreaElement.setAttribute(SingleFile.SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME, "");
|
|
selectedAreaElement.setAttribute(SingleFile.SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME, "");
|
|
|
selectedAreaElement.querySelectorAll("*").forEach(element => element.setAttribute(SingleFile.SELECTED_CONTENT_ATTRIBUTE_NAME, ""));
|
|
selectedAreaElement.querySelectorAll("*").forEach(element => element.setAttribute(SingleFile.SELECTED_CONTENT_ATTRIBUTE_NAME, ""));
|