forked from qt-creator/qt-creator
TextEditor: fix emitting TextEditorWidget::tooltipRequested
... if no handler is responsible for the tooltip at the cursor position.
Since the CyclicSuggestionHoverHandler is added to all text editors we
need to make sure that this signal is still emitted for editor
implementations that rely on this signal.
Amends 6547d1e776
Change-Id: Iee3e316826ae253109ba4ea64781012ad55c1c23
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -35,7 +35,6 @@ public:
|
|||||||
bool lastHelpItemAppliesTo(const TextEditorWidget *widget) const;
|
bool lastHelpItemAppliesTo(const TextEditorWidget *widget) const;
|
||||||
const QString &toolTip() const;
|
const QString &toolTip() const;
|
||||||
|
|
||||||
protected:
|
|
||||||
enum {
|
enum {
|
||||||
Priority_None = 0,
|
Priority_None = 0,
|
||||||
Priority_Tooltip = 5,
|
Priority_Tooltip = 5,
|
||||||
@@ -43,6 +42,8 @@ protected:
|
|||||||
Priority_Diagnostic = 20,
|
Priority_Diagnostic = 20,
|
||||||
Priority_Suggestion = 40
|
Priority_Suggestion = 40
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
void setPriority(int priority);
|
void setPriority(int priority);
|
||||||
int priority() const;
|
int priority() const;
|
||||||
|
|
||||||
|
@@ -361,6 +361,7 @@ class HoverHandlerRunner
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Callback = std::function<void(TextEditorWidget *, BaseHoverHandler *, int)>;
|
using Callback = std::function<void(TextEditorWidget *, BaseHoverHandler *, int)>;
|
||||||
|
using FallbackCallback = std::function<void(TextEditorWidget *)>;
|
||||||
|
|
||||||
HoverHandlerRunner(TextEditorWidget *widget, QList<BaseHoverHandler *> &handlers)
|
HoverHandlerRunner(TextEditorWidget *widget, QList<BaseHoverHandler *> &handlers)
|
||||||
: m_widget(widget)
|
: m_widget(widget)
|
||||||
@@ -370,10 +371,12 @@ public:
|
|||||||
|
|
||||||
~HoverHandlerRunner() { abortHandlers(); }
|
~HoverHandlerRunner() { abortHandlers(); }
|
||||||
|
|
||||||
void startChecking(const QTextCursor &textCursor, const Callback &callback)
|
void startChecking(const QTextCursor &textCursor, const Callback &callback, const FallbackCallback &fallbackCallback)
|
||||||
{
|
{
|
||||||
if (m_handlers.empty())
|
if (m_handlers.empty()) {
|
||||||
|
fallbackCallback(m_widget);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Does the last handler still applies?
|
// Does the last handler still applies?
|
||||||
const int documentRevision = textCursor.document()->revision();
|
const int documentRevision = textCursor.document()->revision();
|
||||||
@@ -390,6 +393,7 @@ public:
|
|||||||
m_documentRevision = documentRevision;
|
m_documentRevision = documentRevision;
|
||||||
m_position = position;
|
m_position = position;
|
||||||
m_callback = callback;
|
m_callback = callback;
|
||||||
|
m_fallbackCallback = fallbackCallback;
|
||||||
|
|
||||||
restart();
|
restart();
|
||||||
}
|
}
|
||||||
@@ -437,6 +441,8 @@ public:
|
|||||||
if (m_bestHandler) {
|
if (m_bestHandler) {
|
||||||
m_lastHandlerInfo = LastHandlerInfo(m_bestHandler, m_documentRevision, m_position);
|
m_lastHandlerInfo = LastHandlerInfo(m_bestHandler, m_documentRevision, m_position);
|
||||||
m_callback(m_widget, m_bestHandler, m_position);
|
m_callback(m_widget, m_bestHandler, m_position);
|
||||||
|
} else {
|
||||||
|
m_fallbackCallback(m_widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,7 +472,7 @@ private:
|
|||||||
// Re-initialize process data
|
// Re-initialize process data
|
||||||
m_currentHandlerIndex = 0;
|
m_currentHandlerIndex = 0;
|
||||||
m_bestHandler = nullptr;
|
m_bestHandler = nullptr;
|
||||||
m_highestHandlerPriority = -1;
|
m_highestHandlerPriority = BaseHoverHandler::Priority_None;
|
||||||
|
|
||||||
// Start checking
|
// Start checking
|
||||||
checkNext();
|
checkNext();
|
||||||
@@ -498,12 +504,13 @@ private:
|
|||||||
|
|
||||||
// invocation data
|
// invocation data
|
||||||
Callback m_callback;
|
Callback m_callback;
|
||||||
|
FallbackCallback m_fallbackCallback;
|
||||||
int m_position = -1;
|
int m_position = -1;
|
||||||
int m_documentRevision = -1;
|
int m_documentRevision = -1;
|
||||||
|
|
||||||
// processing data
|
// processing data
|
||||||
int m_currentHandlerIndex = -1;
|
int m_currentHandlerIndex = -1;
|
||||||
int m_highestHandlerPriority = -1;
|
int m_highestHandlerPriority = BaseHoverHandler::Priority_None;
|
||||||
BaseHoverHandler *m_bestHandler = nullptr;
|
BaseHoverHandler *m_bestHandler = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -4610,15 +4617,13 @@ void TextEditorWidgetPrivate::processTooltipRequest(const QTextCursor &c)
|
|||||||
if (handled)
|
if (handled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_hoverHandlers.isEmpty()) {
|
|
||||||
emit q->tooltipRequested(toolTipPoint, c.position());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto callback = [toolTipPoint](TextEditorWidget *widget, BaseHoverHandler *handler, int) {
|
const auto callback = [toolTipPoint](TextEditorWidget *widget, BaseHoverHandler *handler, int) {
|
||||||
handler->showToolTip(widget, toolTipPoint);
|
handler->showToolTip(widget, toolTipPoint);
|
||||||
};
|
};
|
||||||
m_hoverHandlerRunner.startChecking(c, callback);
|
const auto fallback = [toolTipPoint, position = c.position()](TextEditorWidget *widget) {
|
||||||
|
emit widget->tooltipRequested(toolTipPoint, position);
|
||||||
|
};
|
||||||
|
m_hoverHandlerRunner.startChecking(c, callback, fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditorWidgetPrivate::processAnnotaionTooltipRequest(const QTextBlock &block,
|
bool TextEditorWidgetPrivate::processAnnotaionTooltipRequest(const QTextBlock &block,
|
||||||
@@ -9760,11 +9765,6 @@ void TextEditorWidget::contextHelpItem(const IContext::HelpCallback &callback)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QString fallbackWordUnderCursor = Text::wordUnderCursor(textCursor());
|
const QString fallbackWordUnderCursor = Text::wordUnderCursor(textCursor());
|
||||||
if (d->m_hoverHandlers.isEmpty()) {
|
|
||||||
callback(fallbackWordUnderCursor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto hoverHandlerCallback = [fallbackWordUnderCursor, callback](
|
const auto hoverHandlerCallback = [fallbackWordUnderCursor, callback](
|
||||||
TextEditorWidget *widget, BaseHoverHandler *handler, int position) {
|
TextEditorWidget *widget, BaseHoverHandler *handler, int position) {
|
||||||
handler->contextHelpId(widget, position,
|
handler->contextHelpId(widget, position,
|
||||||
@@ -9776,7 +9776,11 @@ void TextEditorWidget::contextHelpItem(const IContext::HelpCallback &callback)
|
|||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
d->m_hoverHandlerRunner.startChecking(textCursor(), hoverHandlerCallback);
|
const auto fallback = [callback, fallbackWordUnderCursor](TextEditorWidget *) {
|
||||||
|
callback(fallbackWordUnderCursor);
|
||||||
|
};
|
||||||
|
|
||||||
|
d->m_hoverHandlerRunner.startChecking(textCursor(), hoverHandlerCallback, fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidget::setContextHelpItem(const HelpItem &item)
|
void TextEditorWidget::setContextHelpItem(const HelpItem &item)
|
||||||
|
Reference in New Issue
Block a user