|
@@ -116,8 +116,9 @@ this.singlefile.ui = this.singlefile.ui || (() => {
|
|
|
|
|
|
|
|
function markSelectedContent() {
|
|
function markSelectedContent() {
|
|
|
const selection = getSelection();
|
|
const selection = getSelection();
|
|
|
|
|
+ let selectionFound;
|
|
|
for (let indexRange = 0; indexRange < selection.rangeCount; indexRange++) {
|
|
for (let indexRange = 0; indexRange < selection.rangeCount; indexRange++) {
|
|
|
- let selectionFound = false;
|
|
|
|
|
|
|
+ let rangeSelectionFound = false;
|
|
|
let range = selection.getRangeAt(indexRange);
|
|
let range = selection.getRangeAt(indexRange);
|
|
|
if (range && range.commonAncestorContainer) {
|
|
if (range && range.commonAncestorContainer) {
|
|
|
const treeWalker = document.createTreeWalker(range.commonAncestorContainer);
|
|
const treeWalker = document.createTreeWalker(range.commonAncestorContainer);
|
|
@@ -125,7 +126,8 @@ this.singlefile.ui = this.singlefile.ui || (() => {
|
|
|
markSelectedNode(treeWalker.currentNode);
|
|
markSelectedNode(treeWalker.currentNode);
|
|
|
} else {
|
|
} else {
|
|
|
while (treeWalker.currentNode != range.endContainer) {
|
|
while (treeWalker.currentNode != range.endContainer) {
|
|
|
- if (selectionFound || treeWalker.currentNode == range.startContainer || treeWalker.currentNode == range.endContainer) {
|
|
|
|
|
|
|
+ if (rangeSelectionFound || treeWalker.currentNode == range.startContainer || treeWalker.currentNode == range.endContainer) {
|
|
|
|
|
+ rangeSelectionFound = true;
|
|
|
selectionFound = true;
|
|
selectionFound = true;
|
|
|
markSelectedNode(treeWalker.currentNode);
|
|
markSelectedNode(treeWalker.currentNode);
|
|
|
}
|
|
}
|
|
@@ -134,7 +136,7 @@ this.singlefile.ui = this.singlefile.ui || (() => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return Boolean(selection.rangeCount);
|
|
|
|
|
|
|
+ return selectionFound;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function markSelectedNode(node) {
|
|
function markSelectedNode(node) {
|
|
@@ -146,7 +148,7 @@ this.singlefile.ui = this.singlefile.ui || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function markSelectedArea(selectedAreaElement) {
|
|
function markSelectedArea(selectedAreaElement) {
|
|
|
- selectedAreaElement.querySelectorAll("*").forEach(element => element.setAttribute(SingleFile.SELECTED_CONTENT_ATTRIBUTE_NAME, ""));
|
|
|
|
|
|
|
+ selectedAreaElement.querySelectorAll("*").forEach(element => markSelectedNode(element));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function unmarkSelection() {
|
|
function unmarkSelection() {
|