Fixed tab completion rarely completing the wrong word. (#4735)
* Fixed tab completion rarely completing the wrong word. Fixes: #3101 * Use QSignalBlocker instead of janky bool, add comment about hidden logic * copypasteo
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
- Bugfix: Fixed crash that could occurr when closing the usercard too quickly after blocking or unblocking a user. (#4711)
|
- 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 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 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 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 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)
|
- Dev: Added test cases for emote and tab completion. (#4644)
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
#include "common/Common.hpp"
|
#include "common/Common.hpp"
|
||||||
#include "common/CompletionModel.hpp"
|
#include "common/CompletionModel.hpp"
|
||||||
|
#include "common/QLogging.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
@@ -20,6 +22,19 @@ ResizingTextEdit::ResizingTextEdit()
|
|||||||
QObject::connect(this, &QTextEdit::textChanged, this,
|
QObject::connect(this, &QTextEdit::textChanged, this,
|
||||||
&QWidget::updateGeometry);
|
&QWidget::updateGeometry);
|
||||||
|
|
||||||
|
QObject::connect(this, &QTextEdit::cursorPositionChanged, [this]() {
|
||||||
|
// If tab was pressed and we're completing/replacing the current word,
|
||||||
|
// this code will not even be called, see ResizingTextEdit::keyPressEvent
|
||||||
|
|
||||||
|
if (!this->completionInProgress_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qCDebug(chatterinoCommon)
|
||||||
|
<< "Finishing completion because cursor moved";
|
||||||
|
this->completionInProgress_ = false;
|
||||||
|
});
|
||||||
|
|
||||||
// Whenever the setting for emote completion changes, force a
|
// Whenever the setting for emote completion changes, force a
|
||||||
// refresh on the completion model the next time "Tab" is pressed
|
// refresh on the completion model the next time "Tab" is pressed
|
||||||
getSettings()->prefixOnlyEmoteCompletion.connect([this] {
|
getSettings()->prefixOnlyEmoteCompletion.connect([this] {
|
||||||
@@ -156,8 +171,12 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
|
|||||||
completionModel->refresh(currentCompletionPrefix,
|
completionModel->refresh(currentCompletionPrefix,
|
||||||
this->isFirstWord());
|
this->isFirstWord());
|
||||||
this->completionInProgress_ = true;
|
this->completionInProgress_ = true;
|
||||||
this->completer_->setCompletionPrefix(currentCompletionPrefix);
|
{
|
||||||
this->completer_->complete();
|
// this blocks cursor movement events from resetting tab completion
|
||||||
|
QSignalBlocker dontTriggerCursorMovement(this);
|
||||||
|
this->completer_->setCompletionPrefix(currentCompletionPrefix);
|
||||||
|
this->completer_->complete();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +201,11 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->completer_->complete();
|
{
|
||||||
|
// this blocks cursor movement events from updating tab completion
|
||||||
|
QSignalBlocker dontTriggerCursorMovement(this);
|
||||||
|
this->completer_->complete();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ private:
|
|||||||
* `Tab` pressed again:
|
* `Tab` pressed again:
|
||||||
* - complete ["pog"] to "PogChamp"
|
* - complete ["pog"] to "PogChamp"
|
||||||
*
|
*
|
||||||
* [other key] pressed - updating the input text:
|
* [other key] pressed or cursor moved - updating the input text:
|
||||||
* - set `completionInProgress_ = false`
|
* - set `completionInProgress_ = false`
|
||||||
*/
|
*/
|
||||||
bool completionInProgress_ = false;
|
bool completionInProgress_ = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user