Merge pull request #686 from 23rd/patch-8-fixed-down-arrow

Fixed down key in input field.
This commit is contained in:
pajlada 2018-08-29 10:24:47 +02:00 committed by GitHub
commit 597a8eeb2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -189,8 +189,7 @@ void SplitInput::installKeyPressedEvent()
this->currMsg_ = QString();
this->ui_.textEdit->setText(QString());
this->prevIndex_ = 0;
} else if (this->ui_.textEdit->toPlainText() ==
this->prevMsg_.at(this->prevMsg_.size() - 1)) {
} else if (message == this->prevMsg_.at(this->prevMsg_.size() - 1)) {
this->prevMsg_.removeLast();
}
this->prevIndex_ = this->prevMsg_.size();
@ -230,6 +229,13 @@ void SplitInput::installKeyPressedEvent()
page->selectNextSplit(SplitContainer::Below);
}
} else {
// If user did not write anything before then just do nothing.
if (this->prevMsg_.isEmpty()) {
return;
}
bool cursorToEnd = true;
QString message = ui_.textEdit->toPlainText();
if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
this->prevIndex_ != this->prevMsg_.size()) {
this->prevIndex_++;
@ -237,13 +243,27 @@ void SplitInput::installKeyPressedEvent()
this->prevMsg_.at(this->prevIndex_));
} else {
this->prevIndex_ = this->prevMsg_.size();
if (message == this->prevMsg_.at(this->prevIndex_ - 1)) {
// If user has just come from a message history
// Then simply get currMsg_.
this->ui_.textEdit->setText(this->currMsg_);
} else if (message != this->currMsg_) {
// If user are already in current message
// And type something new
// Then replace currMsg_ with new one.
this->currMsg_ = message;
}
// If user is already in current message
// Then don't touch cursos.
cursorToEnd = (message == this->prevMsg_.at(this->prevIndex_ - 1));
}
if (cursorToEnd) {
QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor);
}
}
} else if (event->key() == Qt::Key_Left) {
if (event->modifiers() == Qt::AltModifier) {
SplitContainer *page = this->split_->getContainer();