forked from qt-creator/qt-creator
TextEditor: Make accidentally activating a link more difficult again
Only follow links under cursor if control was already activated when
pressing the mouse button. This amends
11eea3aae0
which just checks if control is
pressed after releasing the mouse button.
Change-Id: I90d23dd3e5ff63aac7812fad889ad9fb7c052b56
Fixes: QTCREATORBUG-23745
Reviewed-by: Alexis Murzeau <amubtdx@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -549,6 +549,7 @@ public:
|
|||||||
|
|
||||||
QTextBlock foldedBlockAt(const QPoint &pos, QRect *box = nullptr) const;
|
QTextBlock foldedBlockAt(const QPoint &pos, QRect *box = nullptr) const;
|
||||||
|
|
||||||
|
bool isMouseNavigationEvent(QMouseEvent *e) const;
|
||||||
void requestUpdateLink(QMouseEvent *e);
|
void requestUpdateLink(QMouseEvent *e);
|
||||||
void updateLink();
|
void updateLink();
|
||||||
void showLink(const Utils::Link &);
|
void showLink(const Utils::Link &);
|
||||||
@@ -5553,7 +5554,7 @@ void TextEditorWidget::mousePressEvent(QMouseEvent *e)
|
|||||||
if (refactorMarker.callback)
|
if (refactorMarker.callback)
|
||||||
refactorMarker.callback(this);
|
refactorMarker.callback(this);
|
||||||
} else {
|
} else {
|
||||||
d->m_linkPressed = true;
|
d->m_linkPressed = d->isMouseNavigationEvent(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (e->button() == Qt::RightButton) {
|
} else if (e->button() == Qt::RightButton) {
|
||||||
@@ -5572,13 +5573,7 @@ void TextEditorWidget::mousePressEvent(QMouseEvent *e)
|
|||||||
|
|
||||||
void TextEditorWidget::mouseReleaseEvent(QMouseEvent *e)
|
void TextEditorWidget::mouseReleaseEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
if (mouseNavigationEnabled()
|
if (d->m_linkPressed && d->isMouseNavigationEvent(e) && e->button() == Qt::LeftButton) {
|
||||||
&& d->m_linkPressed
|
|
||||||
&& e->modifiers() & Qt::ControlModifier
|
|
||||||
&& !(e->modifiers() & Qt::ShiftModifier)
|
|
||||||
&& e->button() == Qt::LeftButton
|
|
||||||
) {
|
|
||||||
|
|
||||||
EditorManager::addCurrentPositionToNavigationHistory();
|
EditorManager::addCurrentPositionToNavigationHistory();
|
||||||
bool inNextSplit = ((e->modifiers() & Qt::AltModifier) && !alwaysOpenLinksInNextSplit())
|
bool inNextSplit = ((e->modifiers() & Qt::AltModifier) && !alwaysOpenLinksInNextSplit())
|
||||||
|| (alwaysOpenLinksInNextSplit() && !(e->modifiers() & Qt::AltModifier));
|
|| (alwaysOpenLinksInNextSplit() && !(e->modifiers() & Qt::AltModifier));
|
||||||
@@ -6167,11 +6162,16 @@ bool TextEditorWidget::openLink(const Utils::Link &link, bool inNextSplit)
|
|||||||
Id(), flags);
|
Id(), flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TextEditorWidgetPrivate::isMouseNavigationEvent(QMouseEvent *e) const
|
||||||
|
{
|
||||||
|
return q->mouseNavigationEnabled() && e->modifiers() & Qt::ControlModifier
|
||||||
|
&& !(e->modifiers() & Qt::ShiftModifier);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidgetPrivate::requestUpdateLink(QMouseEvent *e)
|
void TextEditorWidgetPrivate::requestUpdateLink(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
if (!q->mouseNavigationEnabled())
|
if (!isMouseNavigationEvent(e))
|
||||||
return;
|
return;
|
||||||
if (e->modifiers() & Qt::ControlModifier) {
|
|
||||||
// Link emulation behaviour for 'go to definition'
|
// Link emulation behaviour for 'go to definition'
|
||||||
const QTextCursor cursor = q->cursorForPosition(e->pos());
|
const QTextCursor cursor = q->cursorForPosition(e->pos());
|
||||||
|
|
||||||
@@ -6193,7 +6193,6 @@ void TextEditorWidgetPrivate::requestUpdateLink(QMouseEvent *e)
|
|||||||
QTimer::singleShot(0, this, &TextEditorWidgetPrivate::updateLink);
|
QTimer::singleShot(0, this, &TextEditorWidgetPrivate::updateLink);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
clearLink();
|
clearLink();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user