Sfoglia il codice sorgente

fixed selection issues (cf #134)

Gildas 7 anni fa
parent
commit
f969052f9b
1 ha cambiato i file con 17 aggiunte e 13 eliminazioni
  1. 17 13
      extension/ui/content/content-ui.js

+ 17 - 13
extension/ui/content/content-ui.js

@@ -121,22 +121,26 @@ this.singlefile.ui = this.singlefile.ui || (() => {
 			let range = selection.getRangeAt(indexRange);
 			if (range && range.commonAncestorContainer) {
 				const treeWalker = document.createTreeWalker(range.commonAncestorContainer);
-				markSelectedParents(treeWalker.currentNode);
-				if (treeWalker.currentNode == range.endContainer) {
-					selectionFound = true;
-					markSelectedNode(treeWalker.currentNode);
-					treeWalker.currentNode.querySelectorAll("*").forEach(descendantElement => markSelectedNode(descendantElement));
-				} else {
-					let rangeSelectionFound = false;
-					while (treeWalker.currentNode != range.endContainer) {
-						if (rangeSelectionFound || treeWalker.currentNode == range.startContainer || treeWalker.currentNode == range.endContainer) {
-							rangeSelectionFound = true;
-							selectionFound = true;
-							markSelectedNode(treeWalker.currentNode);
-						}
+				let rangeSelectionFound = false;
+				let finished = false;
+				while (!finished) {
+					if (rangeSelectionFound || treeWalker.currentNode == range.startContainer || treeWalker.currentNode == range.endContainer) {
+						rangeSelectionFound = true;
+						selectionFound = true;
+						markSelectedNode(treeWalker.currentNode);
+					}
+					if (treeWalker.currentNode == range.startContainer) {
+						markSelectedParents(treeWalker.currentNode);
+					}
+					if (treeWalker.currentNode == range.endContainer) {
+						finished = true;
+					} else {
 						treeWalker.nextNode();
 					}
 				}
+				if (treeWalker.currentNode == range.endContainer && treeWalker.currentNode.querySelectorAll) {
+					treeWalker.currentNode.querySelectorAll("*").forEach(descendantElement => markSelectedNode(descendantElement));
+				}
 			}
 		}
 		return selectionFound;