Skip to content

Commit

Permalink
Add shortcut (Ctrl+Shift+J) to invoke SyncTeX at the cursor position (#…
Browse files Browse the repository at this point in the history
…412)

To customize the shortcut, use actionJump_To_PDF in shortcuts.ini
  • Loading branch information
stloeffler committed Dec 29, 2019
1 parent f632880 commit 281f5e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/CompletingEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<QAction*>(sender());
if (act) {
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/CompletingEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/CompletingEdit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
<string>Ctrl+Shift+Backtab</string>
</property>
</action>
<action name="actionJump_To_PDF">
<property name="text">
<string>Jump to PDF</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+J</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down

0 comments on commit 281f5e8

Please sign in to comment.