Skip to content

Commit

Permalink
Quote SyncTeX path to allow for whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
struan-robertson committed Sep 17, 2024
1 parent d448ea9 commit d426958
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit d426958

Please sign in to comment.