Skip to content

Commit

Permalink
honor -named-dest and -page when file was loaded via restoring the se…
Browse files Browse the repository at this point in the history
…ssion (fixes #3836)
  • Loading branch information
kjk committed Nov 2, 2023
1 parent 4b58a85 commit cf6939d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/SumatraStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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();
Expand Down

0 comments on commit cf6939d

Please sign in to comment.