diff --git a/src/lib/index.ts b/src/lib/index.ts index 7329cf5..ca5191e 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -240,16 +240,13 @@ export class PDFPlusLib { } getPDFViewerChildAssociatedWithNode(node: Node) { - // for (const [viewerEl, child] of this.plugin.pdfViwerChildren) { - // if (viewerEl.contains(node)) return child; - // } let child: PDFViewerChild | undefined; const el = node.instanceOf(HTMLElement) ? node : node.parentElement; if (el) { - const viewerEl = el.closest('.pdf-viewer'); - if (viewerEl) { - child = this.plugin.pdfViewerChildren.get(viewerEl); + const pdfContainerEl = el.closest('.pdf-container'); + if (pdfContainerEl) { + child = this.plugin.pdfViewerChildren.get(pdfContainerEl); } } diff --git a/src/main.ts b/src/main.ts index 64c8a40..c343092 100644 --- a/src/main.ts +++ b/src/main.ts @@ -70,7 +70,7 @@ export default class PDFPlus extends Plugin { lastCopiedDestInfo: { file: TFile, destArray: DestArray } | { file: TFile, destName: string } | null = null; vimrc: string | null = null; citationIdRegex: RegExp; - /** Maps a `div.pdf-viewer` element to the corresponding `PDFViewerChild` object. */ + /** Maps a `div.pdf-container` element to the corresponding `PDFViewerChild` object. */ // In most use cases of this map, the goal is also achieved by using lib.workspace.iteratePDFViewerChild. // However, a PDF embed inside a Canvas text node cannot be handled by the function, so we need this map. pdfViewerChildren: Map = new Map(); @@ -550,8 +550,8 @@ export default class PDFPlus extends Plugin { private registerEvents() { // keep this.pdfViewerChildren up-to-date this.registerEvent(this.app.workspace.on('layout-change', () => { - for (const viewerEl of this.pdfViewerChildren.keys()) { - if (!viewerEl?.isShown()) this.pdfViewerChildren.delete(viewerEl); + for (const pdfContainerEl of this.pdfViewerChildren.keys()) { + if (!pdfContainerEl?.isShown()) this.pdfViewerChildren.delete(pdfContainerEl); } })); diff --git a/src/patchers/pdf-internals.ts b/src/patchers/pdf-internals.ts index 93b4c94..757e271 100644 --- a/src/patchers/pdf-internals.ts +++ b/src/patchers/pdf-internals.ts @@ -228,9 +228,9 @@ const patchPDFViewerChild = (plugin: PDFPlus, child: PDFViewerChild) => { }, onResize(old) { return function (this: PDFViewerChild) { - const viewerEl = this.containerEl.querySelector('.pdf-viewer'); - if (viewerEl) { - plugin.pdfViewerChildren.set(viewerEl, this); + const pdfContainerEl = this.containerEl.querySelector('.pdf-container'); + if (pdfContainerEl) { + plugin.pdfViewerChildren.set(pdfContainerEl, this); } return old.call(this); @@ -276,9 +276,9 @@ const patchPDFViewerChild = (plugin: PDFPlus, child: PDFViewerChild) => { await old.call(this, file, subpath); } - const viewerEl = this.containerEl.querySelector('.pdf-viewer'); - if (viewerEl) { - plugin.pdfViewerChildren.set(viewerEl, this); + const pdfContainerEl = this.containerEl.querySelector('.pdf-container'); + if (pdfContainerEl) { + plugin.pdfViewerChildren.set(pdfContainerEl, this); } this.bib?.unload();