Skip to content

Commit f6c6321

Browse files
Copilotdroidmonkey
andcommitted
Fix markdown preview persistence and enable external links in attachment editor
Co-authored-by: droidmonkey <[email protected]>
1 parent 0b97b78 commit f6c6321

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace
4848
TextAttachmentsPreviewWidget::TextAttachmentsPreviewWidget(QWidget* parent)
4949
: QWidget(parent)
5050
, m_ui(new Ui::TextAttachmentsPreviewWidget())
51+
, m_userManuallySelectedType(false)
5152
{
5253
m_ui->setupUi(this);
5354

@@ -63,6 +64,8 @@ void TextAttachmentsPreviewWidget::openAttachment(attachments::Attachment attach
6364
}
6465

6566
m_attachment = std::move(attachments);
67+
// Reset manual selection flag when opening a new attachment
68+
m_userManuallySelectedType = false;
6669

6770
updateUi();
6871
}
@@ -88,10 +91,13 @@ void TextAttachmentsPreviewWidget::initTypeCombobox()
8891
filterProxyMode->sort(0, Qt::SortOrder::DescendingOrder);
8992
m_ui->typeComboBox->setModel(filterProxyMode);
9093

91-
connect(m_ui->typeComboBox,
92-
QOverload<int>::of(&QComboBox::currentIndexChanged),
93-
this,
94-
&TextAttachmentsPreviewWidget::onTypeChanged);
94+
connect(m_ui->typeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) {
95+
m_userManuallySelectedType = true;
96+
onTypeChanged(index);
97+
});
98+
99+
// Configure text browser to open external links
100+
m_ui->previewTextBrowser->setOpenExternalLinks(true);
95101

96102
m_ui->typeComboBox->setCurrentIndex(m_ui->typeComboBox->findData(PlainText));
97103

@@ -100,11 +106,17 @@ void TextAttachmentsPreviewWidget::initTypeCombobox()
100106

101107
void TextAttachmentsPreviewWidget::updateUi()
102108
{
103-
if (!m_attachment.name.isEmpty()) {
109+
// Only auto-select format based on file extension if user hasn't manually chosen one
110+
if (!m_userManuallySelectedType && !m_attachment.name.isEmpty()) {
104111
const auto mimeType = Tools::getMimeType(QFileInfo(m_attachment.name));
105112

106113
auto index = m_ui->typeComboBox->findData(ConvertToPreviewTextType(mimeType));
107-
m_ui->typeComboBox->setCurrentIndex(index);
114+
if (index >= 0) {
115+
// Temporarily block signals to avoid triggering manual selection flag
116+
m_ui->typeComboBox->blockSignals(true);
117+
m_ui->typeComboBox->setCurrentIndex(index);
118+
m_ui->typeComboBox->blockSignals(false);
119+
}
108120
}
109121

110122
onTypeChanged(m_ui->typeComboBox->currentIndex());

src/gui/entry/attachments/TextAttachmentsPreviewWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ private slots:
5858
QScopedPointer<Ui::TextAttachmentsPreviewWidget> m_ui;
5959

6060
attachments::Attachment m_attachment;
61+
bool m_userManuallySelectedType;
6162
};

0 commit comments

Comments
 (0)