Allow editing via up and down arrows
This commit is contained in:
parent
29a71741f4
commit
f6b5b24d64
@ -209,6 +209,39 @@ Rectangle {
|
|||||||
} else if (event.key == Qt.Key_Down && popup.opened) {
|
} else if (event.key == Qt.Key_Down && popup.opened) {
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
popup.down();
|
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
|
background: null
|
||||||
|
@ -499,6 +499,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
|
|||||||
data(event, static_cast<int>(ProportionalHeight)));
|
data(event, static_cast<int>(ProportionalHeight)));
|
||||||
m.insert(names[Id], data(event, static_cast<int>(Id)));
|
m.insert(names[Id], data(event, static_cast<int>(Id)));
|
||||||
m.insert(names[State], data(event, static_cast<int>(State)));
|
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[IsEncrypted], data(event, static_cast<int>(IsEncrypted)));
|
||||||
m.insert(names[IsRoomEncrypted], data(event, static_cast<int>(IsRoomEncrypted)));
|
m.insert(names[IsRoomEncrypted], data(event, static_cast<int>(IsRoomEncrypted)));
|
||||||
m.insert(names[ReplyTo], data(event, static_cast<int>(ReplyTo)));
|
m.insert(names[ReplyTo], data(event, static_cast<int>(ReplyTo)));
|
||||||
@ -1550,6 +1552,17 @@ TimelineModel::setEdit(QString newEdit)
|
|||||||
if (edit_.startsWith('m'))
|
if (edit_.startsWith('m'))
|
||||||
return;
|
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) {
|
if (edit_ != newEdit) {
|
||||||
auto ev = events.get(newEdit.toStdString(), "");
|
auto ev = events.get(newEdit.toStdString(), "");
|
||||||
if (ev && mtx::accessors::sender(*ev) == http::client()->user_id().to_string()) {
|
if (ev && mtx::accessors::sender(*ev) == http::client()->user_id().to_string()) {
|
||||||
@ -1584,8 +1597,14 @@ TimelineModel::resetEdit()
|
|||||||
if (!edit_.isEmpty()) {
|
if (!edit_.isEmpty()) {
|
||||||
edit_ = "";
|
edit_ = "";
|
||||||
emit editChanged(edit_);
|
emit editChanged(edit_);
|
||||||
input()->setText("");
|
nhlog::ui()->debug("Restoring: {}", textBeforeEdit.toStdString());
|
||||||
resetReply();
|
input()->setText(textBeforeEdit);
|
||||||
|
textBeforeEdit.clear();
|
||||||
|
if (replyBeforeEdit.isEmpty())
|
||||||
|
resetReply();
|
||||||
|
else
|
||||||
|
setReply(replyBeforeEdit);
|
||||||
|
replyBeforeEdit.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,6 +337,7 @@ private:
|
|||||||
|
|
||||||
QString currentId, currentReadId;
|
QString currentId, currentReadId;
|
||||||
QString reply_, edit_;
|
QString reply_, edit_;
|
||||||
|
QString textBeforeEdit, replyBeforeEdit;
|
||||||
std::vector<QString> typingUsers_;
|
std::vector<QString> typingUsers_;
|
||||||
|
|
||||||
TimelineViewManager *manager_;
|
TimelineViewManager *manager_;
|
||||||
|
Loading…
Reference in New Issue
Block a user