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
1 changed files with 6 additions and 5 deletions

View File

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