From 281f5e809517bba8f84e744a1b2d4bd33724f535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20L=C3=B6ffler?= Date: Sun, 29 Dec 2019 17:33:41 +0100 Subject: [PATCH] Add shortcut (Ctrl+Shift+J) to invoke SyncTeX at the cursor position (#412) To customize the shortcut, use actionJump_To_PDF in shortcuts.ini --- src/CompletingEdit.cpp | 14 +++++++++++--- src/CompletingEdit.h | 3 ++- src/CompletingEdit.ui | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/CompletingEdit.cpp b/src/CompletingEdit.cpp index 5732b3375..4d68b3cfd 100644 --- a/src/CompletingEdit.cpp +++ b/src/CompletingEdit.cpp @@ -83,9 +83,10 @@ CompletingEdit::CompletingEdit(QWidget *parent /* = nullptr */) connect(TWApp::instance(), SIGNAL(highlightLineOptionChanged()), this, SLOT(resetExtraSelections())); setupUi(this); + connect(actionJump_To_PDF, SIGNAL(triggered()), this, SLOT(jumpToPdf())); // As these actions are not used in menus/toolbars, we need to manually add // them to the widget for TWUtils::installCustomShortcuts to work - insertActions(nullptr, {actionNext_Completion, actionPrevious_Completion, actionNext_Completion_Placeholder, actionPrevious_Completion_Placeholder}); + insertActions(nullptr, {actionNext_Completion, actionPrevious_Completion, actionNext_Completion_Placeholder, actionPrevious_Completion_Placeholder, actionJump_To_PDF}); #ifdef Q_OS_DARWIN // Backwards compatibility @@ -1066,7 +1067,14 @@ void CompletingEdit::loadCompletionFiles(QCompleter *theCompleter) theCompleter->setModel(model); } -void CompletingEdit::jumpToPdf() +void CompletingEdit::jumpToPdf(QTextCursor pos) +{ + if (pos.isNull()) + pos = textCursor(); + emit syncClick(pos.blockNumber() + 1, pos.positionInBlock()); +} + +void CompletingEdit::jumpToPdfFromContextMenu() { QAction *act = qobject_cast(sender()); if (act) { @@ -1083,7 +1091,7 @@ void CompletingEdit::contextMenuEvent(QContextMenuEvent *event) QTextCursor cur = cursorForPosition(event->pos()); act->setData(QVariant(QPoint(cur.positionInBlock(), cur.blockNumber() + 1))); - connect(act, SIGNAL(triggered()), this, SLOT(jumpToPdf())); + connect(act, SIGNAL(triggered()), this, SLOT(jumpToPdfFromContextMenu())); menu->insertSeparator(menu->actions().first()); menu->insertAction(menu->actions().first(), act); diff --git a/src/CompletingEdit.h b/src/CompletingEdit.h index 78f9336d4..3dd3b51e5 100644 --- a/src/CompletingEdit.h +++ b/src/CompletingEdit.h @@ -117,7 +117,8 @@ private slots: void addToDictionary(); void ignoreWord(); void resetExtraSelections(); - void jumpToPdf(); + void jumpToPdf(QTextCursor pos = {}); + void jumpToPdfFromContextMenu(); void updateLineNumberArea(const QRect&, int); private: diff --git a/src/CompletingEdit.ui b/src/CompletingEdit.ui index 606bd71df..06d584c34 100644 --- a/src/CompletingEdit.ui +++ b/src/CompletingEdit.ui @@ -42,6 +42,14 @@ Ctrl+Shift+Backtab + + + Jump to PDF + + + Ctrl+Shift+J + +