Commit b192d18e authored by David Schulz's avatar David Schulz

TextEditor: Caching links at cursor position.

Reducing the number of calls to findLinkAt() when hovering over
text.

Task-number: QTCREATORBUG-12573
Change-Id: I679ee7d9599071e1e3ea20cc028440df6dad0d25
Reviewed-by: default avatarNikita Baryshnikov <nib952051@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 4b5315bd
......@@ -393,6 +393,7 @@ public:
TextEditorWidget::Link m_currentLink;
bool m_linkPressed;
TextEditorWidget::Link m_lastLinkUnderCursor;
QRegExp m_searchExpr;
FindFlags m_findFlags;
......@@ -5385,9 +5386,9 @@ bool TextEditorWidget::openLink(const Link &link, bool inNextSplit)
void TextEditorWidgetPrivate::updateLink(QMouseEvent *e)
{
bool linkFound = false;
if (q->mouseNavigationEnabled() && e->modifiers() & Qt::ControlModifier) {
if (!q->mouseNavigationEnabled())
return;
if (e->modifiers() & Qt::ControlModifier) {
// Link emulation behaviour for 'go to definition'
const QTextCursor cursor = q->cursorForPosition(e->pos());
......@@ -5399,16 +5400,22 @@ void TextEditorWidgetPrivate::updateLink(QMouseEvent *e)
onText = q->cursorRect(nextPos).right() >= e->x();
}
const TextEditorWidget::Link link = q->findLinkAt(cursor, false);
if (onText && link.hasValidLinkText()) {
showLink(link);
linkFound = true;
if (cursor.position() < m_lastLinkUnderCursor.linkTextStart
|| cursor.position() > m_lastLinkUnderCursor.linkTextEnd) {
m_lastLinkUnderCursor = q->findLinkAt(cursor, false);
}
}
if (!linkFound)
if (onText && m_lastLinkUnderCursor.hasValidLinkText()) {
showLink(m_lastLinkUnderCursor);
} else {
clearLink();
// setting position to prevent multiple calls to findLinkAt for the same position
m_lastLinkUnderCursor.linkTextStart = cursor.position();
m_lastLinkUnderCursor.linkTextEnd = cursor.position();
}
} else {
clearLink();
}
}
void TextEditorWidgetPrivate::showLink(const TextEditorWidget::Link &link)
......@@ -5430,6 +5437,7 @@ void TextEditorWidgetPrivate::showLink(const TextEditorWidget::Link &link)
void TextEditorWidgetPrivate::clearLink()
{
m_lastLinkUnderCursor = TextEditorWidget::Link();
if (!m_currentLink.hasValidLinkText())
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment