From c6aae13a9e0db3c4d6eacb3efe5e27408cf9519d Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Thu, 20 Aug 2026 11:57:20 +0200 Subject: [PATCH] fix: the page count survives switching the pane layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pm-pagecount listener sat on the hosts[0] element, which Svelte replaces when the pane layout changes (multi-page grid, split view). The editor view moves to the new host, the listener died with the old one — numPages froze, so no new page ever appeared in the grid. Listen on the view's own DOM instead, which is only ever re-parented. --- src/lib/components/Editor.svelte | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index 8ab1b4c..d7b00ce 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -1097,7 +1097,9 @@ import { EMPTY_PAGE_DECOR, type PageDecor } from '../storage/pageDecor'; }, }); - hosts[0].addEventListener('pm-pagecount', onPageCount); + // On the view's own DOM, not hosts[0]: switching the pane layout replaces the + // host element, and a listener there would go down with it. + editor.view.dom.addEventListener('pm-pagecount', onPageCount); document.fonts?.addEventListener('loadingdone', repaginateOnFontLoad); document.fonts?.ready.then(repaginateOnFontLoad); // Seed the scaled footprint before the first paint (so the page is centered, not @@ -1313,9 +1315,9 @@ import { EMPTY_PAGE_DECOR, type PageDecor } from '../storage/pageDecor'; cancelAnimationFrame(marginRecalcRaf); cancelAnimationFrame(marksRecalcRaf); cancelAnimationFrame(tableUiRaf); + editor?.view.dom.removeEventListener('pm-pagecount', onPageCount); editor?.destroy(); resetHistoryLog(); - hosts[0]?.removeEventListener('pm-pagecount', onPageCount); document.fonts?.removeEventListener('loadingdone', repaginateOnFontLoad); });