diff options
author | bobzel <zzzman@gmail.com> | 2021-03-25 21:42:32 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-03-25 21:42:32 -0400 |
commit | baa2152a35bac6e0a18ff916817af9bb566a549f (patch) | |
tree | f148b6a166d0181ccd23db7497780e59c809d12a /src | |
parent | e2b0df8e1d91578af7b97fb36bd029104a51dd01 (diff) |
fixed dragging documents so that the scroll position of pdfs/etc is maintained during the drag
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/DragManager.ts | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts index dc95193ea..17dd85a9f 100644 --- a/src/client/util/DragManager.ts +++ b/src/client/util/DragManager.ts @@ -363,6 +363,7 @@ export namespace DragManager { const dragElements = eles.map(ele => { if (!ele.parentNode) dragDiv.appendChild(ele); const dragElement = ele.parentNode === dragDiv ? ele : ele.cloneNode(true) as HTMLElement; + const rect = ele.getBoundingClientRect(); const scaleX = rect.width / ele.offsetWidth, scaleY = ele.offsetHeight ? rect.height / ele.offsetHeight : scaleX; @@ -394,15 +395,6 @@ export namespace DragManager { const pdfBox = dragElement.getElementsByTagName("canvas"); const pdfBoxSrc = ele.getElementsByTagName("canvas"); Array.from(pdfBox).map((pb, i) => pb.getContext('2d')!.drawImage(pdfBoxSrc[i], 0, 0)); - const pdfView = dragElement.getElementsByClassName("pdfViewer-viewer"); - const pdfViewSrc = ele.getElementsByClassName("pdfViewer-viewer"); - const tops = Array.from(pdfViewSrc).map(p => p.scrollTop); - const oldopacity = dragElement.style.opacity; - dragElement.style.opacity = "0"; - setTimeout(() => { - dragElement.style.opacity = oldopacity; - Array.from(pdfView).map((v, i) => v.scrollTo({ top: tops[i] })); - }, 0); } if (dragElement.hasAttribute("style")) (dragElement as any).style.pointerEvents = "none"; const set = dragElement.getElementsByTagName('*'); @@ -412,6 +404,19 @@ export namespace DragManager { } dragDiv.appendChild(dragElement); + if (dragElement !== ele) { + const children = Array.from(ele.children); + const dchildren = Array.from(dragElement.children); + while (children.length) { + const child = children.pop(); + const dchild = dchildren.pop(); + if (child?.children) { + children.push(...(Array.from(child.children))); + dchildren.push(...(Array.from(dchild!.children))); + } + if (child?.scrollTop) dchild!.scrollTop = child.scrollTop; + } + } return dragElement; }); |