Up arrow always edits last available message.

Fixes #4480.
This commit is contained in:
John Preston 2018-03-09 15:18:28 +03:00
parent 6bd5301828
commit e6c0f0f774
4 changed files with 26 additions and 14 deletions

View File

@ -1223,9 +1223,6 @@ void History::clearSendAction(not_null<UserData*> from) {
void History::mainViewRemoved(
not_null<HistoryBlock*> block,
not_null<HistoryView::Element*> view) {
if (lastSentMsg == view->data()) {
lastSentMsg = nullptr;
}
if (_joinedMessage == view->data()) {
_joinedMessage = nullptr;
}
@ -2271,6 +2268,21 @@ MsgId History::msgIdForRead() const {
: result;
}
HistoryItem *History::lastSentMessage() const {
if (!loadedAtBottom()) {
return nullptr;
}
for (const auto &block : base::reversed(blocks)) {
for (const auto &message : base::reversed(block->messages)) {
const auto item = message->data();
if (IsServerMsgId(item->id) && item->out()) {
return item;
}
}
}
return nullptr;
}
void History::resizeToWidth(int newWidth) {
const auto resizeAllItems = (_width != newWidth);
@ -2517,7 +2529,6 @@ void History::unloadBlocks() {
void History::clearBlocks(bool leaveItems) {
_unreadBarView = nullptr;
_firstUnreadView = nullptr;
lastSentMsg = nullptr;
_joinedMessage = nullptr;
if (scrollTopItem) {

View File

@ -242,6 +242,7 @@ public:
MsgId minMsgId() const;
MsgId maxMsgId() const;
MsgId msgIdForRead() const;
HistoryItem *lastSentMessage() const;
void resizeToWidth(int newWidth);
int height() const;
@ -351,7 +352,6 @@ public:
std::deque<std::unique_ptr<HistoryBlock>> blocks;
not_null<PeerData*> peer;
HistoryItem *lastSentMsg = nullptr;
typedef QList<HistoryItem*> NotifyQueue;
NotifyQueue notifies;

View File

@ -5153,13 +5153,16 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) {
}
} else if (e->key() == Qt::Key_Up) {
if (!(e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier))) {
if (_history
&& _history->lastSentMsg
&& _history->lastSentMsg->allowsEdit(unixtime())) {
if (_field->isEmpty() && !_editMsgId && !_replyToId && _history->lastSentMsg) {
editMessage(_history->lastSentMsg);
return;
}
const auto item = _history
? _history->lastSentMessage()
: nullptr;
if (item
&& item->allowsEdit(unixtime())
&& _field->isEmpty()
&& !_editMsgId
&& !_replyToId) {
editMessage(item);
return;
}
_scroll->keyPressEvent(e);
} else if ((e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier)) == Qt::ControlModifier) {

View File

@ -1345,8 +1345,6 @@ void MainWidget::sendMessage(const MessageToSend &message) {
history->sendRequestId);
}
history->lastSentMsg = lastMessage;
finishForwarding(history);
}