summary refs log tree commit diff
path: root/src/timeline/InputBar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeline/InputBar.cpp')
-rw-r--r--src/timeline/InputBar.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp

index ab0fc3d7..d5a6a1dd 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp
@@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + #include "InputBar.h" #include <QClipboard> @@ -123,6 +127,20 @@ InputBar::insertMimeData(const QMimeData *md) } void +InputBar::setText(QString newText) +{ + if (history_.empty()) + history_.push_front(newText); + else + history_.front() = newText; + history_index_ = 0; + + if (history_.size() == INPUT_HISTORY_SIZE) + history_.pop_back(); + + emit textChanged(newText); +} +void InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, QString text_) { if (text_.isEmpty()) @@ -180,6 +198,10 @@ InputBar::send() if (text().trimmed().isEmpty()) return; + nhlog::ui()->debug("Send: {}", text().toStdString()); + + auto wasEdit = !room->edit().isEmpty(); + if (text().startsWith('/')) { int command_end = text().indexOf(' '); if (command_end == -1) @@ -195,12 +217,10 @@ InputBar::send() message(text()); } - nhlog::ui()->debug("Send: {}", text().toStdString()); - - if (history_.size() == INPUT_HISTORY_SIZE) - history_.pop_back(); - history_.push_front(""); - history_index_ = 0; + if (!wasEdit) { + history_.push_front(""); + setText(""); + } } void @@ -256,12 +276,10 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown) if (!room->reply().isEmpty()) { text.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } text.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } else if (!room->reply().isEmpty()) { auto related = room->relatedInfo(room->reply()); @@ -291,7 +309,6 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown) text.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, related.related_event}); - room->resetReply(); } room->sendMessageEvent(text, mtx::events::EventType::RoomMessage); @@ -314,12 +331,10 @@ InputBar::emote(QString msg) if (!room->reply().isEmpty()) { emote.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { emote.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(emote, mtx::events::EventType::RoomMessage); @@ -350,12 +365,10 @@ InputBar::image(const QString &filename, if (!room->reply().isEmpty()) { image.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { image.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(image, mtx::events::EventType::RoomMessage); @@ -381,12 +394,10 @@ InputBar::file(const QString &filename, if (!room->reply().isEmpty()) { file.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { file.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(file, mtx::events::EventType::RoomMessage); @@ -413,12 +424,10 @@ InputBar::audio(const QString &filename, if (!room->reply().isEmpty()) { audio.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { audio.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(audio, mtx::events::EventType::RoomMessage); @@ -444,12 +453,10 @@ InputBar::video(const QString &filename, if (!room->reply().isEmpty()) { video.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { video.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(video, mtx::events::EventType::RoomMessage);