Fix a possible crash in translations.

This commit is contained in:
John Preston 2023-09-18 09:50:09 +04:00
parent 21857450f3
commit e1624e5d22

View File

@ -2437,8 +2437,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
: QString(); : QString();
if (isUponSelected > 0) { if (isUponSelected > 0) {
if (!hasCopyRestrictionForSelected() const auto selectedText = getSelectedText();
&& !getSelectedText().empty()) { if (!hasCopyRestrictionForSelected() && !selectedText.empty()) {
_menu->addAction( _menu->addAction(
((isUponSelected > 1) ((isUponSelected > 1)
? tr::lng_context_copy_selected_items(tr::now) ? tr::lng_context_copy_selected_items(tr::now)
@ -2446,13 +2446,14 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
[=] { copySelectedText(); }, [=] { copySelectedText(); },
&st::menuIconCopy); &st::menuIconCopy);
} }
if (!Ui::SkipTranslate(getSelectedText().rich)) { if (!Ui::SkipTranslate(selectedText.rich)) {
const auto peer = item->history()->peer;
_menu->addAction(tr::lng_context_translate_selected({}), [=] { _menu->addAction(tr::lng_context_translate_selected({}), [=] {
_controller->show(Box( _controller->show(Box(
Ui::TranslateBox, Ui::TranslateBox,
item->history()->peer, peer,
MsgId(), MsgId(),
getSelectedText().rich, selectedText.rich,
hasCopyRestrictionForSelected())); hasCopyRestrictionForSelected()));
}, &st::menuIconTranslate); }, &st::menuIconTranslate);
} }