diff --git a/pdf_viewer/main_widget.cpp b/pdf_viewer/main_widget.cpp index 9c139113d..9657f7c5a 100644 --- a/pdf_viewer/main_widget.cpp +++ b/pdf_viewer/main_widget.cpp @@ -4811,32 +4811,30 @@ std::wstring MainWidget::synctex_under_pos(WindowPos position) { if (column < 0) column = 0; int tag = synctex_node_tag(node); const char* file_name = synctex_scanner_get_name(scanner, tag); + // the path returned by synctex is formatted in unix style, for example it is something like this + // in windows: d:/some/path/file.pdf + // this doesn't work with Vimtex for some reason, so here we have to convert the path separators + // to native style and if on windows ensure the drive letter is capitalized QString new_path; -#ifdef Q_OS_WIN - // the path returned by synctex is formatted in unix style, for example it is something like this - // in windows: d:/some/path/file.pdf - // this doesn't work with Vimtex for some reason, so here we have to convert the path separators - // to windows style and make sure the driver letter is capitalized QDir file_path = QDir(file_name); new_path = QDir::toNativeSeparators(file_path.absolutePath()); + +#ifdef Q_OS_WIN new_path[0] = new_path[0].toUpper(); if (VIMTEX_WSL_FIX) { new_path = file_name; } -#else - new_path = file_name; #endif - + // quote to allow for whitespace in path + new_path.prepend("\""); + new_path.append("\""); + std::string line_string = std::to_string(line); std::string column_string = std::to_string(column); if (inverse_search_command.size() > 0) { -#ifdef Q_OS_WIN - QString command = QString::fromStdWString(inverse_search_command).arg(new_path, line_string.c_str(), column_string.c_str()); -#else - QString command = QString::fromStdWString(inverse_search_command).arg(file_name, line_string.c_str(), column_string.c_str()); -#endif + QString command = QString::fromStdWString(inverse_search_command).arg(new_path, line_string.c_str(), column_string.c_str()); QStringList args = QProcess::splitCommand(command); QProcess::startDetached(args[0], args.mid(1)); }