|
// returns true if inverse search was performed |
|
bool OnInverseSearch(MainWindow* win, int x, int y) { |
|
if (!CanAccessDisk() || gPluginMode) { |
|
return false; |
|
} |
|
WindowTab* tab = win->CurrentTab(); |
|
if (!tab || tab->GetEngineType() != kindEngineMupdf) { |
|
return false; |
|
} |
|
DisplayModel* dm = tab->AsFixed(); |
|
|
|
// Clear the last forward-search result |
|
win->fwdSearchMark.rects.Reset(); |
|
InvalidateRect(win->hwndCanvas, nullptr, FALSE); |
|
|
|
// On double-clicking error message will be shown to the user |
|
// if the PDF does not have a synchronization file |
|
if (!dm->pdfSync) { |
|
const char* path = tab->filePath; |
|
int err = Synchronizer::Create(path, dm->GetEngine(), &dm->pdfSync); |
|
if (err == PDFSYNCERR_SYNCFILE_NOTFOUND) { |
|
// We used to warn that "No synchronization file found" at this |
|
// point if gGlobalPrefs->enableTeXEnhancements is set; we no longer |
|
// so do because a double-click has several other meanings |
|
// (selecting a word or an image, navigating quickly using links) |
|
// and showing an unrelated warning in all those cases seems wrong |
|
return false; |
|
} |
|
if (err != PDFSYNCERR_SUCCESS) { |
|
NotificationCreateArgs args; |
|
args.hwndParent = win->hwndCanvas; |
|
args.msg = _TRA("Synchronization file cannot be opened"); |
|
ShowNotification(args); |
|
return true; |
|
} |
|
gGlobalPrefs->enableTeXEnhancements = true; |
|
} |
|
|
|
int pageNo = dm->GetPageNoByPoint(Point(x, y)); |
|
if (!tab->ctrl->ValidPageNo(pageNo)) { |
|
return false; |
|
} |
|
|
|
Point pt = ToPoint(dm->CvtFromScreen(Point(x, y), pageNo)); |
|
AutoFreeStr srcfilepath; |
|
int line = 0; |
|
int col = 0; |
|
int err = dm->pdfSync->DocToSource(pageNo, pt, srcfilepath, &line, &col); |
|
if (err != PDFSYNCERR_SUCCESS) { |
|
NotificationCreateArgs args; |
|
args.hwndParent = win->hwndCanvas; |
|
args.msg = _TRA("No synchronization info at this position"); |
|
ShowNotification(args); |
|
return true; |
|
} |
|
|
|
if (!file::Exists(srcfilepath)) { |
|
// if the source file is missing, check if it's been moved to the same place as |
|
// the PDF document (which happens if all files are moved together) |
|
TempStr altsrcpath = path::GetDirTemp(tab->filePath); |
|
altsrcpath = path::JoinTemp(altsrcpath, path::GetBaseNameTemp(srcfilepath)); |
|
if (!str::Eq(altsrcpath, srcfilepath) && file::Exists(altsrcpath)) { |
|
srcfilepath.SetCopy(altsrcpath); |
|
} |
|
} |
|
|
|
char* inverseSearch = gGlobalPrefs->inverseSearchCmdLine; |
|
if (!inverseSearch) { |
|
Vec<TextEditor*> editors; |
|
DetectTextEditors(editors); |
|
if (editors.Size() > 0) { |
|
inverseSearch = str::DupTemp(editors[0]->openFileCmd); |
|
} |
|
} |
|
|
|
AutoFreeStr cmdLine; |
|
if (inverseSearch) { |
|
cmdLine = BuildOpenFileCmd(inverseSearch, srcfilepath, line, col); |
|
} |
|
|
|
NotificationCreateArgs args; |
|
args.hwndParent = win->hwndCanvas; |
|
args.msg = _TRA("Cannot start inverse search command. Please check the command line in the settings."); |
|
if (!str::IsEmpty(cmdLine.Get())) { |
|
// resolve relative paths with relation to SumatraPDF.exe's directory |
|
char* appDir = GetSelfExeDirTemp(); |
|
AutoCloseHandle process(LaunchProcessInDir(cmdLine, appDir)); |
|
if (!process) { |
|
ShowNotification(args); |
|
} |
|
} else if (gGlobalPrefs->enableTeXEnhancements) { |
|
ShowNotification(args); |
|
} |
|
|
|
return true; |
|
} |
SumatraPDF version
Describe the bug
When the file path contains non-ASCII characters (e.g., Chinese characters), both forward and backward synchronization fail.
Corrected: In backward case, a info message appears: “No synchronization info at this position”.
To Reproduce
Expected behavior
File that reproduces the problem
basic\testENGbasic\testCNTest1 space\testENG1Test1 space\testCN1Test2 中文\testENG2Test2 中文\testCN2add1\test中文Content from the unzipped
testCN1.synctexfile:Content from the unzipped
testCN2.synctexfile:Discussion
testCN1.synctexandtestCN2.synctex:/.s in.synctexfile do not affect synchronization.Directory structure
Screenshots
testENG1 (No3), forward:
testENG2 (No5), forward:
testENG2 (No5), backward:
Relative Code
Forward:
sumatrapdf/src/SearchAndDDE.cpp
Lines 606 to 666 in ab3bd6f
Backward:
sumatrapdf/src/SearchAndDDE.cpp
Lines 509 to 604 in ab3bd6f
Additional context
I suggest making the info messages more distinguishable between forward and backward sync failures for better debugging.
E.g. "[source to PDF] No synchronization info at this position" and "[PDF to source] No synchronization info at this position"
Forward:
sumatrapdf/src/SearchAndDDE.cpp
Line 652 in ab3bd6f
Backward:
sumatrapdf/src/SearchAndDDE.cpp
Line 560 in ab3bd6f
Test files
D2_InverseSearch_issue.zip