Commit 73ee96c6 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: no timed hiding of symbol info tooltip

... since this is an explicitly triggered hover tooltip
parent 335d3c0e
......@@ -52,6 +52,11 @@ public:
* \return text tool tip to be displayed, may be Qt richtext
*/
QString textHint(KTextEditor::View *view, const KTextEditor::Cursor &position) override
{
return showTextHint(view, position, false);
}
QString showTextHint(KTextEditor::View *view, const KTextEditor::Cursor &position, bool manual) override
{
if (!position.isValid()) {
return {};
......@@ -60,7 +65,7 @@ public:
// hack: delayed handling of tooltip on our own, the API is too dumb for a-sync feedback ;=)
if (m_server) {
QPointer<KTextEditor::View> v(view);
auto h = [v, position](const LSPHover &info) {
auto h = [v, position, manual](const LSPHover &info) {
if (!v || info.contents.isEmpty()) {
return;
}
......@@ -76,7 +81,7 @@ public:
// make sure there is no selection, otherwise we interrupt
if (!v->selection()) {
LspTooltip::show(finalTooltip, v->mapToGlobal(v->cursorToCoordinate(position)), v);
LspTooltip::show(finalTooltip, v->mapToGlobal(v->cursorToCoordinate(position)), v, manual ? 0 : 1000);
}
};
......
......@@ -27,6 +27,9 @@ public:
}
virtual void setServer(QSharedPointer<LSPClientServer> server) = 0;
// support additional parameters besides the usual interface signature
virtual QString showTextHint(KTextEditor::View *view, const KTextEditor::Cursor &position, bool manual) = 0;
};
#endif
......@@ -1619,7 +1619,7 @@ public:
{
// trigger manually the normally automagic hover
if (auto activeView = m_mainWindow->activeView()) {
m_hover->textHint(activeView, activeView->cursorPosition());
m_hover->showTextHint(activeView, activeView->cursorPosition(), true);
}
}
......
......@@ -64,9 +64,10 @@ public:
}
}
Tooltip(QWidget *parent)
Tooltip(QWidget *parent, int timeout)
: QTextBrowser(parent)
, hl(document())
, m_hideTimeout(timeout)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::BypassGraphicsProxyWidget | Qt::ToolTip);
setAttribute(Qt::WA_DeleteOnClose, true);
......@@ -185,7 +186,9 @@ public:
protected:
void showEvent(QShowEvent *event) override
{
m_hideTimer.start(1000);
if (m_hideTimeout > 0) {
m_hideTimer.start(m_hideTimeout);
}
QTextBrowser::showEvent(event);
}
......@@ -224,9 +227,10 @@ private:
QPointer<KTextEditor::View> m_view;
QTimer m_hideTimer;
KSyntaxHighlighting::SyntaxHighlighter hl;
int m_hideTimeout;
};
void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v)
void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v, int timeout)
{
if (text.isEmpty())
return;
......@@ -235,7 +239,7 @@ void LspTooltip::show(const QString &text, QPoint pos, KTextEditor::View *v)
return;
}
auto tooltip = new Tooltip(v);
auto tooltip = new Tooltip(v, timeout);
tooltip->show();
tooltip->setView(v);
tooltip->setTooltipText(text);
......
......@@ -21,7 +21,8 @@ class View;
class LspTooltip
{
public:
static void show(const QString &text, QPoint pos, KTextEditor::View *v);
// tooltip hidden after timeout msec (if > 0)
static void show(const QString &text, QPoint pos, KTextEditor::View *v, int timeout);
};
#endif // LSPTOOLTIP_H
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