From cf6939d853deeb0983a50d0dc9915c67ef6e224d Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Fri, 3 Nov 2023 00:39:28 +0100 Subject: [PATCH] honor -named-dest and -page when file was loaded via restoring the session (fixes #3836) --- src/SumatraStartup.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/SumatraStartup.cpp b/src/SumatraStartup.cpp index 107a099f8b5f..21aa5d8ebb1b 100644 --- a/src/SumatraStartup.cpp +++ b/src/SumatraStartup.cpp @@ -273,6 +273,22 @@ static void FlagsEnterFullscreen(const Flags& flags, MainWindow* win) { } } +static void MaybeGoTo(MainWindow* win, const char* destName, int pageNumber) { + if (!win->IsDocLoaded()) { + return; + } + if (destName) { + win->linkHandler->GotoNamedDest(destName); + return; + } + + if (pageNumber > 0) { + if (win->ctrl->ValidPageNo(pageNumber)) { + win->ctrl->GoToPage(pageNumber, false); + } + } +} + static void MaybeStartSearch(MainWindow* win, const char* searchTerm) { if (!win || !searchTerm) { return; @@ -291,14 +307,10 @@ static MainWindow* LoadOnStartup(const char* filePath, const Flags& flags, bool return win; } - if (win->IsDocLoaded() && flags.destName && isFirstWin) { - char* dest = flags.destName; - win->linkHandler->GotoNamedDest(dest); - } else if (win->IsDocLoaded() && flags.pageNumber > 0 && isFirstWin) { - if (win->ctrl->ValidPageNo(flags.pageNumber)) { - win->ctrl->GoToPage(flags.pageNumber, false); - } + if (isFirstWin) { + MaybeGoTo(win, flags.destName, flags.pageNumber); } + bool ok = MaybeMakePluginWindow(win, flags.hwndPluginParent); if (!ok) { return nullptr; @@ -1300,6 +1312,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { } TabsSelect(win, data->tabIndex - 1); if (gGlobalPrefs->lazyLoading) { + // trigger loading of the document ReloadDocument(win, false); } } @@ -1325,6 +1338,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { if (tabToSelect) { SelectTabInWindow(tabToSelect); MaybeStartSearch(tabToSelect->win, flags.search); + MaybeGoTo(win, flags.destName, flags.pageNumber); } nWithDde = (int)gDdeOpenOnStartup.size();