Skip to content

Commit 9452e14

Browse files
committed
Use a 100ms timer for cursor movement fim triggering
This way if you just navigate in the source code up and down, it won't feel laggish. When stopping then the fim will be triggered.
1 parent a56ef1e commit 9452e14

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

llamaplugin.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,24 @@ QRegularExpression LlamaPlugin::s_whitespace_regex("^\\s*$");
5454

5555
LlamaPlugin::LlamaPlugin()
5656
: m_ringUpdateTimer(new QTimer(this))
57+
, m_positionChangedTimer(new QTimer(this))
5758
, m_networkManager(new QNetworkAccessManager(this))
5859
{
5960
connect(m_ringUpdateTimer, &QTimer::timeout, this, &LlamaPlugin::ring_update);
61+
m_positionChangedTimer->setSingleShot(true);
62+
connect(m_positionChangedTimer,
63+
&QTimer::timeout,
64+
this,
65+
&LlamaPlugin::handleCursorPositionChangedDelayed);
6066
}
6167

6268
LlamaPlugin::~LlamaPlugin()
6369
{
6470
disconnect(m_ringUpdateTimer, &QTimer::timeout, this, &LlamaPlugin::ring_update);
71+
disconnect(m_positionChangedTimer,
72+
&QTimer::timeout,
73+
this,
74+
&LlamaPlugin::handleCursorPositionChangedDelayed);
6575
}
6676

6777
FilePath LlamaPlugin::getTranslationFilePath(const QString &translationFile)
@@ -232,11 +242,18 @@ void LlamaPlugin::handleEditorAboutToClose(Core::IEditor *editor)
232242

233243
void LlamaPlugin::handleCursorPositionChanged()
234244
{
235-
TextEditorWidget *editor = TextEditorWidget::currentTextEditorWidget();
236-
if (!editor || !settings().enableLlamaCpp())
245+
if (!settings().enableLlamaCpp())
237246
return;
238247

239248
hideCompletionHint();
249+
m_positionChangedTimer->start(100);
250+
}
251+
252+
void LlamaPlugin::handleCursorPositionChangedDelayed()
253+
{
254+
TextEditorWidget *editor = TextEditorWidget::currentTextEditorWidget();
255+
if (!editor)
256+
return;
240257

241258
QTextCursor cursor = editor->textCursor();
242259
int pos_x = cursor.positionInBlock();

llamaplugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private slots:
4343
void handleCurrentEditorChanged(Core::IEditor *editor);
4444
void handleEditorAboutToClose(Core::IEditor *editor);
4545
void handleCursorPositionChanged();
46+
void handleCursorPositionChangedDelayed();
4647
void handleDocumentSaved(Core::IDocument *document);
4748

4849
private:
@@ -101,6 +102,7 @@ private slots:
101102
// State tracking
102103
QPoint m_lastPos;
103104
QTimer *m_ringUpdateTimer;
105+
QTimer *m_positionChangedTimer;
104106
QNetworkAccessManager *m_networkManager;
105107
std::unique_ptr<QNetworkReply> m_fimReply;
106108

0 commit comments

Comments
 (0)