Don't insert "data:image.." after image paste cancel.

This commit is contained in:
John Preston 2024-07-04 08:57:41 +04:00
parent b377c02ad3
commit b648548001
4 changed files with 7 additions and 2 deletions

View file

@ -5668,7 +5668,7 @@ bool HistoryWidget::confirmSendingFiles(
cursor.setPosition(position, QTextCursor::KeepAnchor); cursor.setPosition(position, QTextCursor::KeepAnchor);
} }
_field->setTextCursor(cursor); _field->setTextCursor(cursor);
if (!insertTextOnCancel.isEmpty()) { if (Ui::InsertTextOnImageCancel(insertTextOnCancel)) {
_field->textCursor().insertText(insertTextOnCancel); _field->textCursor().insertText(insertTextOnCancel);
} }
})); }));

View file

@ -3415,7 +3415,7 @@ Fn<void()> ComposeControls::restoreTextCallback(
cursor.setPosition(position, QTextCursor::KeepAnchor); cursor.setPosition(position, QTextCursor::KeepAnchor);
} }
_field->setTextCursor(cursor); _field->setTextCursor(cursor);
if (!insertTextOnCancel.isEmpty()) { if (Ui::InsertTextOnImageCancel(insertTextOnCancel)) {
_field->textCursor().insertText(insertTextOnCancel); _field->textCursor().insertText(insertTextOnCancel);
} }
}); });

View file

@ -82,6 +82,10 @@ bool CanBeInAlbumType(PreparedFile::Type type, AlbumType album) {
Unexpected("AlbumType in CanBeInAlbumType."); Unexpected("AlbumType in CanBeInAlbumType.");
} }
bool InsertTextOnImageCancel(const QString &text) {
return !text.isEmpty() && !text.startsWith(u"data:image"_q);
}
PreparedList PreparedList::Reordered( PreparedList PreparedList::Reordered(
PreparedList &&list, PreparedList &&list,
std::vector<int> order) { std::vector<int> order) {

View file

@ -88,6 +88,7 @@ struct PreparedFile {
}; };
[[nodiscard]] bool CanBeInAlbumType(PreparedFile::Type type, AlbumType album); [[nodiscard]] bool CanBeInAlbumType(PreparedFile::Type type, AlbumType album);
[[nodiscard]] bool InsertTextOnImageCancel(const QString &text);
struct PreparedList { struct PreparedList {
enum class Error { enum class Error {