Clipper: Fixes #2294: Clipping selection in some cases would not work, when that selection contains multiple code blocks

pull/2479/head
Laurent Cozic 2020-02-08 12:16:49 +00:00
parent 0229686203
commit 1e190bbe70
1 changed files with 11 additions and 2 deletions

View File

@ -325,9 +325,18 @@
hardcodePreStyles(document);
preProcessDocument(document);
const range = window.getSelection().getRangeAt(0);
const container = document.createElement('div');
container.appendChild(range.cloneContents());
const rangeCount = window.getSelection().rangeCount;
// Even when the user makes only one selection, Firefox might report multiple selections
// so we need to process them all.
// Fixes https://github.com/laurent22/joplin/issues/2294
for (let i = 0; i < rangeCount; i++) {
const range = window.getSelection().getRangeAt(i);
container.appendChild(range.cloneContents());
}
const imageSizes = getImageSizes(document, true);
const imageIndexes = {};
cleanUpElement(convertToMarkup, container, imageSizes, imageIndexes);