fix: Invalid/Dangling completion after updating input (#4072)

This commit is contained in:
nerix
2022-10-22 11:42:46 +02:00
committed by GitHub
parent dd6cb80ab9
commit 457c5725da
4 changed files with 33 additions and 0 deletions
+5
View File
@@ -246,6 +246,11 @@ void ResizingTextEdit::setCompleter(QCompleter *c)
this, &ResizingTextEdit::insertCompletion);
}
void ResizingTextEdit::resetCompletion()
{
this->completionInProgress_ = false;
}
void ResizingTextEdit::insertCompletion(const QString &completion)
{
if (this->completer_->widget() != this)
+23
View File
@@ -24,6 +24,11 @@ public:
void setCompleter(QCompleter *c);
QCompleter *getCompleter() const;
/**
* Resets a completion for this text if one was is progress.
* See `completionInProgress_`.
*/
void resetCompletion();
protected:
int heightForWidth(int) const override;
@@ -41,6 +46,24 @@ private:
QString textUnderCursor(bool *hadSpace = nullptr) const;
QCompleter *completer_ = nullptr;
/**
* This is true if a completion was done but the user didn't type yet,
* and might want to press `Tab` again to get the next completion
* on the original text.
*
* For example:
*
* input: "pog"
* `Tab` pressed:
* - complete to "PogBones"
* - retain "pog" for next completion
* - set `completionInProgress_ = true`
* `Tab` pressed again:
* - complete ["pog"] to "PogChamp"
*
* [other key] pressed - updating the input text:
* - set `completionInProgress_ = false`
*/
bool completionInProgress_ = false;
bool eventFilter(QObject *obj, QEvent *event) override;