Fixed down key in input field.

This commit is contained in:
23rd 2018-08-27 21:12:38 +03:00
parent 70199e00d2
commit f6d0cc9e6b

View file

@ -186,8 +186,7 @@ void SplitInput::installKeyPressedEvent()
this->currMsg_ = QString(); this->currMsg_ = QString();
this->ui_.textEdit->setText(QString()); this->ui_.textEdit->setText(QString());
this->prevIndex_ = 0; this->prevIndex_ = 0;
} else if (this->ui_.textEdit->toPlainText() == } else if (message == this->prevMsg_.at(this->prevMsg_.size() - 1)) {
this->prevMsg_.at(this->prevMsg_.size() - 1)) {
this->prevMsg_.removeLast(); this->prevMsg_.removeLast();
} }
this->prevIndex_ = this->prevMsg_.size(); this->prevIndex_ = this->prevMsg_.size();
@ -227,6 +226,13 @@ void SplitInput::installKeyPressedEvent()
page->selectNextSplit(SplitContainer::Below); page->selectNextSplit(SplitContainer::Below);
} }
} else { } 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) && if (this->prevIndex_ != (this->prevMsg_.size() - 1) &&
this->prevIndex_ != this->prevMsg_.size()) { this->prevIndex_ != this->prevMsg_.size()) {
this->prevIndex_++; this->prevIndex_++;
@ -234,13 +240,29 @@ void SplitInput::installKeyPressedEvent()
this->prevMsg_.at(this->prevIndex_)); this->prevMsg_.at(this->prevIndex_));
} else { } else {
this->prevIndex_ = this->prevMsg_.size(); 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_); this->ui_.textEdit->setText(this->currMsg_);
} else if (message != this->currMsg_) {
// If user is already in current message
// And type something new
// Then replace currMsg_ with new one.
this->currMsg_ = message;
} else {
// If user is already in current message
// And no changed text
// Then don't touch cursos.
cursorToEnd = false;
}
} }
if (cursorToEnd) {
QTextCursor cursor = this->ui_.textEdit->textCursor(); QTextCursor cursor = this->ui_.textEdit->textCursor();
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
this->ui_.textEdit->setTextCursor(cursor); this->ui_.textEdit->setTextCursor(cursor);
} }
}
} else if (event->key() == Qt::Key_Left) { } else if (event->key() == Qt::Key_Left) {
if (event->modifiers() == Qt::AltModifier) { if (event->modifiers() == Qt::AltModifier) {
SplitContainer *page = this->split_->getContainer(); SplitContainer *page = this->split_->getContainer();