mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 09:41:41 -05:00
Fixed moving cursor when using reply shortcuts.
- Fixed #6038. - Slightly refactored comparison of modifiers.
This commit is contained in:
parent
f945e88d13
commit
6c2479c09f
2 changed files with 41 additions and 28 deletions
|
@ -124,6 +124,10 @@ constexpr auto kSaveDraftAnywayTimeout = 5000;
|
||||||
constexpr auto kSaveCloudDraftIdleTimeout = 14000;
|
constexpr auto kSaveCloudDraftIdleTimeout = 14000;
|
||||||
constexpr auto kRecordingUpdateDelta = crl::time(100);
|
constexpr auto kRecordingUpdateDelta = crl::time(100);
|
||||||
constexpr auto kRefreshSlowmodeLabelTimeout = crl::time(200);
|
constexpr auto kRefreshSlowmodeLabelTimeout = crl::time(200);
|
||||||
|
constexpr auto kCommonModifiers = 0
|
||||||
|
| Qt::ShiftModifier
|
||||||
|
| Qt::MetaModifier
|
||||||
|
| Qt::ControlModifier;
|
||||||
|
|
||||||
ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() {
|
ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() {
|
||||||
return [](ChannelData *channel, MsgId msgId) {
|
return [](ChannelData *channel, MsgId msgId) {
|
||||||
|
@ -397,6 +401,7 @@ HistoryWidget::HistoryWidget(
|
||||||
_parsedLinks = std::move(parsed);
|
_parsedLinks = std::move(parsed);
|
||||||
checkPreview();
|
checkPreview();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
_field->rawTextEdit()->installEventFilter(this);
|
||||||
_field->rawTextEdit()->installEventFilter(_fieldAutocomplete);
|
_field->rawTextEdit()->installEventFilter(_fieldAutocomplete);
|
||||||
_field->setMimeDataHook([=](
|
_field->setMimeDataHook([=](
|
||||||
not_null<const QMimeData*> data,
|
not_null<const QMimeData*> data,
|
||||||
|
@ -3601,6 +3606,16 @@ bool HistoryWidget::insertBotCommand(const QString &cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistoryWidget::eventFilter(QObject *obj, QEvent *e) {
|
bool HistoryWidget::eventFilter(QObject *obj, QEvent *e) {
|
||||||
|
if (e->type() == QEvent::KeyPress) {
|
||||||
|
const auto k = static_cast<QKeyEvent*>(e);
|
||||||
|
if ((k->modifiers() & kCommonModifiers) == Qt::ControlModifier) {
|
||||||
|
if (k->key() == Qt::Key_Up) {
|
||||||
|
return replyToPreviousMessage();
|
||||||
|
} else if (k->key() == Qt::Key_Down) {
|
||||||
|
return replyToNextMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if ((obj == _historyDown || obj == _unreadMentions) && e->type() == QEvent::Wheel) {
|
if ((obj == _historyDown || obj == _unreadMentions) && e->type() == QEvent::Wheel) {
|
||||||
return _scroll->viewportEvent(e);
|
return _scroll->viewportEvent(e);
|
||||||
}
|
}
|
||||||
|
@ -5419,6 +5434,7 @@ void HistoryWidget::mousePressEvent(QMouseEvent *e) {
|
||||||
void HistoryWidget::keyPressEvent(QKeyEvent *e) {
|
void HistoryWidget::keyPressEvent(QKeyEvent *e) {
|
||||||
if (!_history) return;
|
if (!_history) return;
|
||||||
|
|
||||||
|
const auto commonModifiers = e->modifiers() & kCommonModifiers;
|
||||||
if (e->key() == Qt::Key_Escape) {
|
if (e->key() == Qt::Key_Escape) {
|
||||||
e->ignore();
|
e->ignore();
|
||||||
} else if (e->key() == Qt::Key_Back) {
|
} else if (e->key() == Qt::Key_Back) {
|
||||||
|
@ -5428,14 +5444,9 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) {
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
} else if (e->key() == Qt::Key_PageUp) {
|
} else if (e->key() == Qt::Key_PageUp) {
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
} else if (e->key() == Qt::Key_Down) {
|
} else if (e->key() == Qt::Key_Down && !commonModifiers) {
|
||||||
if (!(e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier))) {
|
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
} else if ((e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier)) == Qt::ControlModifier) {
|
} else if (e->key() == Qt::Key_Up && !commonModifiers) {
|
||||||
replyToNextMessage();
|
|
||||||
}
|
|
||||||
} else if (e->key() == Qt::Key_Up) {
|
|
||||||
if (!(e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier))) {
|
|
||||||
const auto item = _history
|
const auto item = _history
|
||||||
? _history->lastSentMessage()
|
? _history->lastSentMessage()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
@ -5448,9 +5459,6 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_scroll->keyPressEvent(e);
|
_scroll->keyPressEvent(e);
|
||||||
} else if ((e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier)) == Qt::ControlModifier) {
|
|
||||||
replyToPreviousMessage();
|
|
||||||
}
|
|
||||||
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
||||||
if (!_botStart->isHidden()) {
|
if (!_botStart->isHidden()) {
|
||||||
sendBotStartCommand();
|
sendBotStartCommand();
|
||||||
|
@ -5499,9 +5507,9 @@ void HistoryWidget::handlePeerMigration() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::replyToPreviousMessage() {
|
bool HistoryWidget::replyToPreviousMessage() {
|
||||||
if (!_history || _editMsgId) {
|
if (!_history || _editMsgId) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
const auto fullId = FullMsgId(
|
const auto fullId = FullMsgId(
|
||||||
_history->channelId(),
|
_history->channelId(),
|
||||||
|
@ -5512,17 +5520,20 @@ void HistoryWidget::replyToPreviousMessage() {
|
||||||
const auto previous = previousView->data();
|
const auto previous = previousView->data();
|
||||||
Ui::showPeerHistoryAtItem(previous);
|
Ui::showPeerHistoryAtItem(previous);
|
||||||
replyToMessage(previous);
|
replyToMessage(previous);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (const auto previous = _history->lastMessage()) {
|
} else if (const auto previous = _history->lastMessage()) {
|
||||||
Ui::showPeerHistoryAtItem(previous);
|
Ui::showPeerHistoryAtItem(previous);
|
||||||
replyToMessage(previous);
|
replyToMessage(previous);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::replyToNextMessage() {
|
bool HistoryWidget::replyToNextMessage() {
|
||||||
if (!_history || _editMsgId) {
|
if (!_history || _editMsgId) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
const auto fullId = FullMsgId(
|
const auto fullId = FullMsgId(
|
||||||
_history->channelId(),
|
_history->channelId(),
|
||||||
|
@ -5537,8 +5548,10 @@ void HistoryWidget::replyToNextMessage() {
|
||||||
clearHighlightMessages();
|
clearHighlightMessages();
|
||||||
cancelReply(false);
|
cancelReply(false);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistoryWidget::showSlowmodeError() {
|
bool HistoryWidget::showSlowmodeError() {
|
||||||
|
|
|
@ -513,8 +513,8 @@ private:
|
||||||
void applyInlineBotQuery(UserData *bot, const QString &query);
|
void applyInlineBotQuery(UserData *bot, const QString &query);
|
||||||
|
|
||||||
void cancelReplyAfterMediaSend(bool lastKeyboardUsed);
|
void cancelReplyAfterMediaSend(bool lastKeyboardUsed);
|
||||||
void replyToPreviousMessage();
|
bool replyToPreviousMessage();
|
||||||
void replyToNextMessage();
|
bool replyToNextMessage();
|
||||||
[[nodiscard]] bool showSlowmodeError();
|
[[nodiscard]] bool showSlowmodeError();
|
||||||
|
|
||||||
void hideSelectorControlsAnimated();
|
void hideSelectorControlsAnimated();
|
||||||
|
|
Loading…
Add table
Reference in a new issue