From b648548001866158420cda364f61c19dd86752b4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 4 Jul 2024 08:57:41 +0400 Subject: [PATCH] Don't insert "data:image.." after image paste cancel. --- Telegram/SourceFiles/history/history_widget.cpp | 2 +- .../history/view/controls/history_view_compose_controls.cpp | 2 +- Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp | 4 ++++ Telegram/SourceFiles/ui/chat/attach/attach_prepare.h | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index fe0610daf..0a3c5a064 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5668,7 +5668,7 @@ bool HistoryWidget::confirmSendingFiles( cursor.setPosition(position, QTextCursor::KeepAnchor); } _field->setTextCursor(cursor); - if (!insertTextOnCancel.isEmpty()) { + if (Ui::InsertTextOnImageCancel(insertTextOnCancel)) { _field->textCursor().insertText(insertTextOnCancel); } })); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 779f0386b..09aa2178e 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -3415,7 +3415,7 @@ Fn ComposeControls::restoreTextCallback( cursor.setPosition(position, QTextCursor::KeepAnchor); } _field->setTextCursor(cursor); - if (!insertTextOnCancel.isEmpty()) { + if (Ui::InsertTextOnImageCancel(insertTextOnCancel)) { _field->textCursor().insertText(insertTextOnCancel); } }); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp index e3f90912f..505fa455b 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp @@ -82,6 +82,10 @@ bool CanBeInAlbumType(PreparedFile::Type type, AlbumType album) { Unexpected("AlbumType in CanBeInAlbumType."); } +bool InsertTextOnImageCancel(const QString &text) { + return !text.isEmpty() && !text.startsWith(u"data:image"_q); +} + PreparedList PreparedList::Reordered( PreparedList &&list, std::vector order) { diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_prepare.h b/Telegram/SourceFiles/ui/chat/attach/attach_prepare.h index 49fd71fa1..c1fb3a379 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_prepare.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_prepare.h @@ -88,6 +88,7 @@ struct PreparedFile { }; [[nodiscard]] bool CanBeInAlbumType(PreparedFile::Type type, AlbumType album); +[[nodiscard]] bool InsertTextOnImageCancel(const QString &text); struct PreparedList { enum class Error {