mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-10-21 22:49:51 -04:00
fix(pdf): clear text layer before re-render to stop duplicated spans (v0.5.3)
TextLayer appends into the container without clearing it, so any re-render of the same page doc (zoom settle, spread-scale update) stacked a second span set at sub-pixel-shifted positions — selection text reads doubled. Clear the container (stale spans + previous endOfContent helper) before each TextLayer render.
This commit is contained in:
1 parent
b7597d6159
commit
7796b05582
2 files changed
+7
-1
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "foliate-js",
|
||||
"version": "0.5.2",
|
||||
"version": "0.5.3",
|
||||
"description": "Render e-books in the browser",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -36,6 +36,12 @@ const render = async (page, doc, zoom) => {
|
||||
doc.querySelector("#canvas").replaceChildren(doc.adoptNode(canvas));
|
||||
|
||||
const container = doc.querySelector(".textLayer");
|
||||
// TextLayer appends into the container without clearing it, so any
|
||||
// re-render of the same page doc (zoom settle, spread-scale update)
|
||||
// stacked a second span set over the old one (sub-pixel shifted —
|
||||
// selection text read doubled). Clear stale spans and the previous
|
||||
// endOfContent helper before rendering fresh.
|
||||
container.replaceChildren();
|
||||
const textLayer = new pdfjsLib.TextLayer({
|
||||
textContentSource: await page.streamTextContent(),
|
||||
container,
|
||||
|
||||
Reference in new issue
Block a user