Fix text input restoring after edits
This commit is contained in:
parent
f6b5b24d64
commit
345dc1e61f
@ -177,7 +177,6 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
TimelineManager.timeline.input.send();
|
||||
messageInput.clear();
|
||||
event.accepted = true;
|
||||
} else if (event.key == Qt.Key_Tab) {
|
||||
event.accepted = true;
|
||||
@ -334,7 +333,6 @@ Rectangle {
|
||||
ToolTip.text: qsTr("Send")
|
||||
onClicked: {
|
||||
TimelineManager.timeline.input.send();
|
||||
messageInput.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,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_)
|
||||
{
|
||||
@ -202,6 +216,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)
|
||||
@ -217,12 +235,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
|
||||
@ -278,12 +294,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());
|
||||
@ -313,7 +327,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);
|
||||
@ -336,12 +349,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);
|
||||
@ -372,12 +383,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);
|
||||
@ -403,12 +412,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);
|
||||
@ -435,12 +442,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);
|
||||
@ -466,12 +471,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);
|
||||
|
@ -41,7 +41,7 @@ public slots:
|
||||
QString text() const;
|
||||
QString previousText();
|
||||
QString nextText();
|
||||
void setText(QString newText) { emit textChanged(newText); }
|
||||
void setText(QString newText);
|
||||
|
||||
void send();
|
||||
void paste(bool fromMouse);
|
||||
|
@ -355,4 +355,6 @@ TimelineModel::sendMessageEvent(const T &content, mtx::events::EventType eventTy
|
||||
msgCopy.content = content;
|
||||
msgCopy.type = eventType;
|
||||
emit newMessageToSend(msgCopy);
|
||||
resetReply();
|
||||
resetEdit();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user