Added arrow Up and Down cycling through past messages.

This commit is contained in:
Cranken 2017-07-24 11:40:37 +02:00
parent 15c14c5008
commit 33a58903f0
2 changed files with 24 additions and 1 deletions

View file

@ -59,10 +59,32 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget)
} }
c->sendMessage(textInput.toPlainText()); c->sendMessage(textInput.toPlainText());
prevMsg.append(textInput.toPlainText());
event->accept(); event->accept();
if(!(event->modifiers() == Qt::ControlModifier)) if(!(event->modifiers() == Qt::ControlModifier))
{ {
textInput.setText(QString()); textInput.setText(QString());
prevIndex = 0;
}
else if(textInput.toPlainText() == prevMsg.at(1))
{
prevMsg.removeFirst();
}
prevIndex = prevMsg.size();
}
else if(event->key() == Qt::Key_Up){
if(prevMsg.size() && prevIndex){
prevIndex--;
textInput.setText(prevMsg.at(prevIndex));
}
}
else if(event->key() == Qt::Key_Down){
if(prevIndex != (prevMsg.size() - 1) && prevIndex != prevMsg.size()){
prevIndex++;
textInput.setText(prevMsg.at(prevIndex));
} else {
prevIndex = prevMsg.size();
textInput.setText(QString());
} }
} }
}); });

View file

@ -38,7 +38,8 @@ private:
ResizingTextEdit textInput; ResizingTextEdit textInput;
QLabel textLengthLabel; QLabel textLengthLabel;
ChatWidgetHeaderButton emotesLabel; ChatWidgetHeaderButton emotesLabel;
QStringList prevMsg;
unsigned int prevIndex = 0;
virtual void refreshTheme() override; virtual void refreshTheme() override;
private slots: private slots: