From 23eb42013be63c90e1ea4a0a1e959603b4505592 Mon Sep 17 00:00:00 2001 From: Cranken Date: Mon, 24 Jul 2017 13:48:34 +0200 Subject: [PATCH] Implemented issues #71 and #72 (#80) * Implemented CTRL-Enter not erasing the input * Added arrow Up and Down cycling through past messages. * Disabled CTRL+Enter adding messages more than once. --- src/widgets/chatwidgetinput.cpp | 28 ++++++++++++++++++++++++++-- src/widgets/chatwidgetinput.hpp | 3 ++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/widgets/chatwidgetinput.cpp b/src/widgets/chatwidgetinput.cpp index acddf1af..6d9b67de 100644 --- a/src/widgets/chatwidgetinput.cpp +++ b/src/widgets/chatwidgetinput.cpp @@ -57,10 +57,34 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget) if (c == nullptr) { return; } - c->sendMessage(textInput.toPlainText()); + prevMsg.append(textInput.toPlainText()); event->accept(); - textInput.setText(QString()); + if(!(event->modifiers() == Qt::ControlModifier)) + { + textInput.setText(QString()); + prevIndex = 0; + } + else if(textInput.toPlainText() == prevMsg.at(prevMsg.size()-1)) + { + prevMsg.removeLast(); + } + 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()); + } } }); diff --git a/src/widgets/chatwidgetinput.hpp b/src/widgets/chatwidgetinput.hpp index 2d0a3e38..48520308 100644 --- a/src/widgets/chatwidgetinput.hpp +++ b/src/widgets/chatwidgetinput.hpp @@ -38,7 +38,8 @@ private: ResizingTextEdit textInput; QLabel textLengthLabel; ChatWidgetHeaderButton emotesLabel; - + QStringList prevMsg; + unsigned int prevIndex = 0; virtual void refreshTheme() override; private slots: