Add input history, enable multi-line input, refactor commands (#119)
This also fixes the transmission of mis-typed commands as messages, fixes inability to send messages that start with a command, and does some initial work towards automatically resizing the input field to fit the input message.
This commit is contained in:
parent
2929d4a3a4
commit
4ccb5ed81f
2 changed files with 135 additions and 61 deletions
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QPaintEvent>
|
||||
#include <QTextEdit>
|
||||
|
|
@ -29,26 +31,36 @@
|
|||
|
||||
namespace msgs = matrix::events::messages;
|
||||
|
||||
static const QString EMOTE_COMMAND("/me ");
|
||||
static const QString JOIN_COMMAND("/join ");
|
||||
|
||||
class FilteredTextEdit : public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QTimer *typingTimer_;
|
||||
|
||||
public:
|
||||
explicit FilteredTextEdit(QWidget *parent = nullptr);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
void stopTyping();
|
||||
|
||||
QSize sizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
|
||||
void submit();
|
||||
|
||||
signals:
|
||||
void enterPressed();
|
||||
void startedTyping();
|
||||
void stoppedTyping();
|
||||
void message(QString);
|
||||
void command(QString name, QString args);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
private:
|
||||
std::deque<QString> true_history_, working_history_;
|
||||
size_t history_index_;
|
||||
QTimer *typingTimer_;
|
||||
|
||||
void textChanged();
|
||||
void afterCompletion(int);
|
||||
};
|
||||
|
||||
class TextInputWidget : public QFrame
|
||||
|
|
@ -62,7 +74,6 @@ public:
|
|||
void stopTyping();
|
||||
|
||||
public slots:
|
||||
void onSendButtonClicked();
|
||||
void openFileSelection();
|
||||
void hideUploadSpinner();
|
||||
void focusLineEdit() { input_->setFocus(); };
|
||||
|
|
@ -84,8 +95,7 @@ protected:
|
|||
|
||||
private:
|
||||
void showUploadSpinner();
|
||||
QString parseEmoteCommand(const QString &cmd);
|
||||
QString parseJoinCommand(const QString &cmd);
|
||||
void command(QString name, QString args);
|
||||
|
||||
QHBoxLayout *topLayout_;
|
||||
FilteredTextEdit *input_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue