Fixed clearing of text field in sections when sending files.

This commit is contained in:
23rd 2021-02-11 21:58:25 +03:00
parent e85394b520
commit bff3291631
4 changed files with 31 additions and 36 deletions

View file

@ -2373,4 +2373,27 @@ void ComposeControls::applyInlineBotQuery(
}
}
Fn<void()> ComposeControls::restoreTextCallback(
const QString &insertTextOnCancel) const {
const auto cursor = _field->textCursor();
const auto position = cursor.position();
const auto anchor = cursor.anchor();
const auto text = getTextWithAppliedMarkdown();
_field->setTextWithTags({});
return crl::guard(_field, [=] {
_field->setTextWithTags(text);
auto cursor = _field->textCursor();
cursor.setPosition(anchor);
if (position != anchor) {
cursor.setPosition(position, QTextCursor::KeepAnchor);
}
_field->setTextCursor(cursor);
if (!insertTextOnCancel.isEmpty()) {
_field->textCursor().insertText(insertTextOnCancel);
}
});
}
} // namespace HistoryView

View file

@ -172,6 +172,8 @@ public:
void applyDraft(
FieldHistoryAction fieldHistoryAction = FieldHistoryAction::Clear);
Fn<void()> restoreTextCallback(const QString &insertTextOnCancel) const;
private:
enum class TextUpdateEvent {
SaveDraft = (1 << 0),

View file

@ -626,19 +626,14 @@ bool RepliesWidget::confirmSendingFiles(
return false;
}
//const auto cursor = _field->textCursor();
//const auto position = cursor.position();
//const auto anchor = cursor.anchor();
const auto text = _composeControls->getTextWithAppliedMarkdown();//_field->getTextWithTags();
using SendLimit = SendFilesBox::SendLimit;
auto box = Box<SendFilesBox>(
controller(),
std::move(list),
text,
_composeControls->getTextWithAppliedMarkdown(),
_history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
Api::SendType::Normal,
SendMenu::Type::SilentOnly); // #TODO replies schedule
_composeControls->setText({});
const auto replyTo = replyToId();
box->setConfirmedCallback(crl::guard(this, [=](
@ -654,18 +649,8 @@ bool RepliesWidget::confirmSendingFiles(
options,
ctrlShiftEnter);
}));
box->setCancelledCallback(crl::guard(this, [=] {
_composeControls->setText(text);
//auto cursor = _field->textCursor();
//cursor.setPosition(anchor);
//if (position != anchor) {
// cursor.setPosition(position, QTextCursor::KeepAnchor);
//}
//_field->setTextCursor(cursor);
//if (!insertTextOnCancel.isEmpty()) {
// _field->textCursor().insertText(insertTextOnCancel);
//}
}));
box->setCancelledCallback(_composeControls->restoreTextCallback(
insertTextOnCancel));
//ActivateWindow(controller());
const auto shown = Ui::show(std::move(box));

View file

@ -350,21 +350,16 @@ bool ScheduledWidget::confirmSendingFiles(
return false;
}
//const auto cursor = _field->textCursor();
//const auto position = cursor.position();
//const auto anchor = cursor.anchor();
const auto text = _composeControls->getTextWithAppliedMarkdown();//_field->getTextWithTags();
using SendLimit = SendFilesBox::SendLimit;
auto box = Box<SendFilesBox>(
controller(),
std::move(list),
text,
_composeControls->getTextWithAppliedMarkdown(),
_history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
CanScheduleUntilOnline(_history->peer)
? Api::SendType::ScheduledToUser
: Api::SendType::Scheduled,
SendMenu::Type::Disabled);
//_field->setTextWithTags({});
box->setConfirmedCallback(crl::guard(this, [=](
Ui::PreparedList &&list,
@ -379,18 +374,8 @@ bool ScheduledWidget::confirmSendingFiles(
options,
ctrlShiftEnter);
}));
//box->setCancelledCallback(crl::guard(this, [=] {
// _field->setTextWithTags(text);
// auto cursor = _field->textCursor();
// cursor.setPosition(anchor);
// if (position != anchor) {
// cursor.setPosition(position, QTextCursor::KeepAnchor);
// }
// _field->setTextCursor(cursor);
// if (!insertTextOnCancel.isEmpty()) {
// _field->textCursor().insertText(insertTextOnCancel);
// }
//}));
box->setCancelledCallback(_composeControls->restoreTextCallback(
insertTextOnCancel));
//ActivateWindow(controller());
const auto shown = Ui::show(std::move(box));