Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed tab completion rarely completing the wrong word. #4735

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Bugfix: Fixed crash that could occurr when closing the usercard too quickly after blocking or unblocking a user. (#4711)
- Bugfix: Fixed highlights sometimes not working after changing sound device, or switching users in your operating system. (#4729)
- Bugfix: Fixed key bindings not showing in context menus on Mac. (#4722)
- Bugfix: Fixed tab completion rarely completing the wrong word. (#4735)
- Dev: Added command to set Qt's logging filter/rules at runtime (`/c2-set-logging-rules`). (#4637)
- Dev: Added the ability to see & load custom themes from the Themes directory. No stable promises are made of this feature, changes might be made that breaks custom themes without notice. (#4570)
- Dev: Added test cases for emote and tab completion. (#4644)
Expand Down
13 changes: 13 additions & 0 deletions src/widgets/helper/ResizingTextEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/Common.hpp"
#include "common/CompletionModel.hpp"
#include "common/QLogging.hpp"
#include "singletons/Settings.hpp"

#include <QMimeData>
Expand All @@ -19,6 +20,15 @@ ResizingTextEdit::ResizingTextEdit()

QObject::connect(this, &QTextEdit::textChanged, this,
&QWidget::updateGeometry);
QObject::connect(this, &QTextEdit::cursorPositionChanged, [this]() {
if (this->updatingText_ || !this->completionInProgress_)
{
return;
}
qCDebug(chatterinoCommon)
<< "Finishing completion because cursor moved";
this->completionInProgress_ = false;
});

// Whenever the setting for emote completion changes, force a
// refresh on the completion model the next time "Tab" is pressed
Expand Down Expand Up @@ -144,6 +154,7 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
{
return;
}
this->updatingText_ = true;

auto *completionModel =
static_cast<CompletionModel *>(this->completer_->model());
Expand All @@ -158,6 +169,7 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
this->completionInProgress_ = true;
this->completer_->setCompletionPrefix(currentCompletionPrefix);
this->completer_->complete();
this->updatingText_ = false;
Mm2PL marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -183,6 +195,7 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
}

this->completer_->complete();
this->updatingText_ = false;
Mm2PL marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down
15 changes: 15 additions & 0 deletions src/widgets/helper/ResizingTextEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ class ResizingTextEdit : public QTextEdit
*/
bool completionInProgress_ = false;

/**
* This is set whenever the tab completion is triggered.
* When this variable is set, moving the cursor will not reset tab completion.
Mm2PL marked this conversation as resolved.
Show resolved Hide resolved
*
* For example:
*
* input: "pog"
* - type Tab to complete to "PogBones"
* - updatingText_ is set to true,
* - text is updated, cursor is moved after the new word
* - updatingText_ is set to false,
* - moving the cursor now would result in completionInProgress_ being set to false
*/
bool updatingText_ = false;

bool eventFilter(QObject *obj, QEvent *event) override;

private slots:
Expand Down
Loading