mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Allow editing via up and down arrows
This commit is contained in:
parent
29a71741f4
commit
f6b5b24d64
3 changed files with 55 additions and 2 deletions
|
@ -209,6 +209,39 @@ Rectangle {
|
|||
} else if (event.key == Qt.Key_Down && popup.opened) {
|
||||
event.accepted = true;
|
||||
popup.down();
|
||||
} else if (event.key == Qt.Key_Up) {
|
||||
if (cursorPosition == 0) {
|
||||
event.accepted = true;
|
||||
var idx = TimelineManager.timeline.edit ? TimelineManager.timeline.idToIndex(TimelineManager.timeline.edit) + 1 : 0;
|
||||
while (true) {
|
||||
var id = TimelineManager.timeline.indexToId(idx);
|
||||
if (!id || TimelineManager.timeline.getDump(id, "").isEditable) {
|
||||
TimelineManager.timeline.edit = id;
|
||||
cursorPosition = 0;
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
} else if (cursorPosition == messageInput.length) {
|
||||
event.accepted = true;
|
||||
cursorPosition = 0;
|
||||
}
|
||||
} else if (event.key == Qt.Key_Down) {
|
||||
if (cursorPosition == 0) {
|
||||
event.accepted = true;
|
||||
cursorPosition = messageInput.length;
|
||||
} else if (cursorPosition == messageInput.length && TimelineManager.timeline.edit) {
|
||||
event.accepted = true;
|
||||
var idx = TimelineManager.timeline.idToIndex(TimelineManager.timeline.edit) - 1;
|
||||
while (true) {
|
||||
var id = TimelineManager.timeline.indexToId(idx);
|
||||
if (!id || TimelineManager.timeline.getDump(id, "").isEditable) {
|
||||
TimelineManager.timeline.edit = id;
|
||||
break;
|
||||
}
|
||||
idx--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
background: null
|
||||
|
|
|
@ -499,6 +499,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
|
|||
data(event, static_cast<int>(ProportionalHeight)));
|
||||
m.insert(names[Id], data(event, static_cast<int>(Id)));
|
||||
m.insert(names[State], data(event, static_cast<int>(State)));
|
||||
m.insert(names[IsEdited], data(event, static_cast<int>(IsEdited)));
|
||||
m.insert(names[IsEditable], data(event, static_cast<int>(IsEditable)));
|
||||
m.insert(names[IsEncrypted], data(event, static_cast<int>(IsEncrypted)));
|
||||
m.insert(names[IsRoomEncrypted], data(event, static_cast<int>(IsRoomEncrypted)));
|
||||
m.insert(names[ReplyTo], data(event, static_cast<int>(ReplyTo)));
|
||||
|
@ -1550,6 +1552,17 @@ TimelineModel::setEdit(QString newEdit)
|
|||
if (edit_.startsWith('m'))
|
||||
return;
|
||||
|
||||
if (newEdit.isEmpty()) {
|
||||
resetEdit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (edit_.isEmpty()) {
|
||||
this->textBeforeEdit = input()->text();
|
||||
this->replyBeforeEdit = reply_;
|
||||
nhlog::ui()->debug("Stored: {}", textBeforeEdit.toStdString());
|
||||
}
|
||||
|
||||
if (edit_ != newEdit) {
|
||||
auto ev = events.get(newEdit.toStdString(), "");
|
||||
if (ev && mtx::accessors::sender(*ev) == http::client()->user_id().to_string()) {
|
||||
|
@ -1584,8 +1597,14 @@ TimelineModel::resetEdit()
|
|||
if (!edit_.isEmpty()) {
|
||||
edit_ = "";
|
||||
emit editChanged(edit_);
|
||||
input()->setText("");
|
||||
resetReply();
|
||||
nhlog::ui()->debug("Restoring: {}", textBeforeEdit.toStdString());
|
||||
input()->setText(textBeforeEdit);
|
||||
textBeforeEdit.clear();
|
||||
if (replyBeforeEdit.isEmpty())
|
||||
resetReply();
|
||||
else
|
||||
setReply(replyBeforeEdit);
|
||||
replyBeforeEdit.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -337,6 +337,7 @@ private:
|
|||
|
||||
QString currentId, currentReadId;
|
||||
QString reply_, edit_;
|
||||
QString textBeforeEdit, replyBeforeEdit;
|
||||
std::vector<QString> typingUsers_;
|
||||
|
||||
TimelineViewManager *manager_;
|
||||
|
|
Loading…
Reference in a new issue