Fixed comma appended to username completion when not at the beginning of the message (#3060)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Paweł
2021-07-24 12:01:50 +02:00
committed by GitHub
parent ae9f92ded9
commit 588ed557f0
13 changed files with 97 additions and 22 deletions
+15 -12
View File
@@ -39,6 +39,19 @@ bool ResizingTextEdit::hasHeightForWidth() const
return true;
}
bool ResizingTextEdit::isFirstWord() const
{
QString plainText = this->toPlainText();
for (int i = this->textCursor().position(); i >= 0; i--)
{
if (plainText[i] == ' ')
{
return false;
}
}
return true;
};
int ResizingTextEdit::heightForWidth(int) const
{
auto margins = this->contentsMargins();
@@ -108,17 +121,6 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
}
QString currentCompletionPrefix = this->textUnderCursor();
bool isFirstWord = [&] {
QString plainText = this->toPlainText();
for (int i = this->textCursor().position(); i >= 0; i--)
{
if (plainText[i] == ' ')
{
return false;
}
}
return true;
}();
// check if there is something to complete
if (currentCompletionPrefix.size() <= 1)
@@ -134,7 +136,8 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event)
// First type pressing tab after modifying a message, we refresh our
// completion model
this->completer_->setModel(completionModel);
completionModel->refresh(currentCompletionPrefix, isFirstWord);
completionModel->refresh(currentCompletionPrefix,
this->isFirstWord());
this->completionInProgress_ = true;
this->completer_->setCompletionPrefix(currentCompletionPrefix);
this->completer_->complete();