mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
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:
parent
703847c9ba
commit
89323ffa1f
|
@ -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 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)
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/CompletionModel.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QMimeDatabase>
|
||||
#include <QObject>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
|
@ -20,6 +22,19 @@ ResizingTextEdit::ResizingTextEdit()
|
|||
QObject::connect(this, &QTextEdit::textChanged, this,
|
||||
&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
|
||||
// refresh on the completion model the next time "Tab" is pressed
|
||||
getSettings()->prefixOnlyEmoteCompletion.connect([this] {
|
||||
|
@ -156,8 +171,12 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
|
|||
completionModel->refresh(currentCompletionPrefix,
|
||||
this->isFirstWord());
|
||||
this->completionInProgress_ = true;
|
||||
{
|
||||
// this blocks cursor movement events from resetting tab completion
|
||||
QSignalBlocker dontTriggerCursorMovement(this);
|
||||
this->completer_->setCompletionPrefix(currentCompletionPrefix);
|
||||
this->completer_->complete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -182,7 +201,11 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
// this blocks cursor movement events from updating tab completion
|
||||
QSignalBlocker dontTriggerCursorMovement(this);
|
||||
this->completer_->complete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
* `Tab` pressed again:
|
||||
* - complete ["pog"] to "PogChamp"
|
||||
*
|
||||
* [other key] pressed - updating the input text:
|
||||
* [other key] pressed or cursor moved - updating the input text:
|
||||
* - set `completionInProgress_ = false`
|
||||
*/
|
||||
bool completionInProgress_ = false;
|
||||
|
|
Loading…
Reference in a new issue