Skip to content

Fix pre-release issues with attachment viewer #12244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 29, 2025

This PR fixes two translation issues in the attachment editor that prevented proper localization:

Issues Fixed

1. "FIT" translation not working in image attachment zoom controls

The "Fit" text in the image attachment widget zoom dropdown was not being translated because QObject::tr("Fit") was called in an anonymous namespace, causing the translation context to be lost.

Before: Translation system couldn't find the proper context for "Fit"
After: tr("Fit") is called directly in the ImageAttachmentsWidget class methods where the translation context is properly available

2. "New Attachment" string not marked for translation

The default name for new attachments was hardcoded as a string literal and never marked for translation.

Before:

constexpr const char* DefaultName = "New Attachment";
auto newFileName = generateUniqueName(DefaultName, m_entryAttachments->keys());

After:

auto newFileName = generateUniqueName(tr("New Attachment"), m_entryAttachments->keys());

Technical Details

  • Moved tr("Fit") calls from anonymous namespace to proper class methods in ImageAttachmentsWidget
  • Replaced hardcoded "New Attachment" string with tr("New Attachment") call in EntryAttachmentsWidget::newAttachments()
  • Updated translation files to include both new translatable strings
  • Removed unused DefaultName constant to keep code clean

The changes are minimal and surgical, following existing code patterns in the project. Both strings now appear correctly in the translation files and will be available for localization.

Fixes #12243.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Several issues in the attachment editor Fix translation issues for "FIT" and "New Attachment" strings in attachment editor Jun 29, 2025
@Copilot Copilot AI requested a review from droidmonkey June 29, 2025 14:41
Copilot finished work on behalf of droidmonkey June 29, 2025 14:41
@droidmonkey
Copy link
Member

Fix the other problems mentioned in the comments of the source issue.

Copy link

codecov bot commented Jun 29, 2025

Codecov Report

❌ Patch coverage is 71.15385% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.25%. Comparing base (56b63a9) to head (1e6766d).

Files with missing lines Patch % Lines
...entry/attachments/TextAttachmentsPreviewWidget.cpp 61.11% 7 Missing ⚠️
...rc/gui/entry/attachments/TextAttachmentsWidget.cpp 84.00% 4 Missing ⚠️
...ui/entry/attachments/TextAttachmentsEditWidget.cpp 25.00% 3 Missing ⚠️
src/gui/entry/EntryAttachmentsWidget.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12244      +/-   ##
===========================================
- Coverage    64.28%   64.25%   -0.03%     
===========================================
  Files          376      376              
  Lines        39309    39339      +30     
===========================================
+ Hits         25268    25275       +7     
- Misses       14041    14064      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor Author

Copilot AI commented Jun 29, 2025

Fix the other problems mentioned in the comments of the source issue.

Fixed the remaining attachment editor issues mentioned in the source issue comments. The changes address:

  1. Markdown preview switching to plaintext: Added state tracking so manual format selection persists during content updates
  2. Links not working: Enabled external links in QTextBrowser so HTML/Markdown links open with Ctrl+click

All existing tests pass and the fixes are minimal surgical changes. Fixed in commit f6c6321.

Copilot finished work on behalf of droidmonkey June 29, 2025 15:11
@droidmonkey droidmonkey marked this pull request as ready for review June 29, 2025 17:45
@Copilot Copilot AI review requested due to automatic review settings June 29, 2025 17:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures proper localization for the attachment editor by moving translation calls into the correct context and marking all hardcoded strings for translation.

  • Use tr("Fit") within ImageAttachmentsWidget methods instead of an anonymous namespace
  • Replace hardcoded "New Attachment" with tr("New Attachment") and remove the unused constant
  • Introduce and reset a manual‐selection flag in TextAttachmentsPreviewWidget, and enable external link opening in its preview browser

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/gui/entry/attachments/TextAttachmentsPreviewWidget.h Added m_userManuallySelectedType member
src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp Initialized and reset manual‐selection flag; enabled external links
src/gui/entry/attachments/ImageAttachmentsWidget.cpp Replaced anonymous‐namespace FitText with tr("Fit")
src/gui/entry/EntryAttachmentsWidget.cpp Swapped hardcoded default name for tr("New Attachment")
share/translations/keepassxc_en.ts Added entries for "New Attachment" and "Fit" translations
Comments suppressed due to low confidence (3)

src/gui/entry/attachments/TextAttachmentsPreviewWidget.h:61

  • Add a brief comment explaining the purpose of m_userManuallySelectedType to improve code readability.
    bool m_userManuallySelectedType;

src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp:67

  • Consider adding a unit test to verify that the manual type selection flag is correctly reset when opening a new attachment.
    // Reset manual selection flag when opening a new attachment

src/gui/entry/attachments/TextAttachmentsPreviewWidget.cpp:100

  • Add a GUI test to confirm that the previewTextBrowser indeed opens external links as expected.
    m_ui->previewTextBrowser->setOpenExternalLinks(true);

@droidmonkey droidmonkey changed the title Fix translation issues for "FIT" and "New Attachment" strings in attachment editor Fix pre-release issues with attachment viewer Jun 29, 2025
@phoerious phoerious added the pr: ai-assisted Pull request contains significant contributions by generative AI label Jun 30, 2025
@droidmonkey droidmonkey added this to the v2.7.11 milestone Jul 4, 2025
@droidmonkey
Copy link
Member

Fixed a bunch of scrolling issues with the preview:

2025-07-04_08-42-52.mp4

@droidmonkey
Copy link
Member

@varjolintu ready for your review/testing

@varjolintu
Copy link
Member

@varjolintu ready for your review/testing

The main text in the PR could've just been "Fixed a few missing translations with.." or something equally compact :)

@droidmonkey
Copy link
Member

Our intern coder gets a little verbose sometimes


void TextAttachmentsWidget::updatePreviewWidget()
{
m_previewVisible = m_previewWidget->width() > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This m_previewWidget->width() > 0 is repeated many times in the file. Maybe create a function for it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of crazy qt doesn't offer an isCollapsed function on the QSplitter. isVisible always returns true as well. Good idea on a defined function.

@@ -65,7 +65,15 @@ void TextAttachmentsWidget::updateWidget()
}

m_editWidget->openAttachment(m_attachment, m_mode);
m_previewWidget->openAttachment(m_attachment, attachments::OpenMode::ReadOnly);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line causes a delay (almost 1 second) when a preview is rendered, even with really small plain text files. Is this necessary? Could we use something like this here, or does it break the scrollbars you mentioned in the issue thread?

if (m_previewWidget->width() > 0) {
    m_previewWidget->openAttachment(m_attachment, attachments::OpenMode::ReadOnly);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But just implementing the above will do the openAttachment() again when the timer hits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was removed because it caused the preview widget to be loaded 3 times when the edit window is first shown and the preview isn't even visible. How can removing it cause more delay? Not sure on your report here.

Copy link
Member

@varjolintu varjolintu Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the videos will help. develop branch:
https://github.com/user-attachments/assets/24993d75-2fc2-4827-b53e-d4d53d85ee99

This PR:
https://github.com/user-attachments/assets/272688bf-12f9-4028-9957-728859d85932

As you can see, this PR has a delay every time Preview dialog is opened.

Copy link
Member

@droidmonkey droidmonkey Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhhhh, just preview, not edit. The delay is from the 500ms timer for when the attachment text is changed.

Copilot AI and others added 6 commits August 4, 2025 23:14
* Update preview panel if manually moved from collapsed position
* Preview is now only updated once on first show instead of three times
* Match edit view scroll position (by percentage) when changed. This ensures the preview remains in relative sync with the edited document, for example when a large amount of HTML reduces down to a short preview document.
* Reset the preview scroll back to it's previous position after re-rendering a change.
* Fix default preview size to be half the width of the edit widget.
@droidmonkey droidmonkey force-pushed the copilot/fix-12243 branch 2 times, most recently from ab3ed28 to 511bad8 Compare August 5, 2025 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n pr: ai-assisted Pull request contains significant contributions by generative AI PRE-RELEASE BUG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Several issues in the attachment editor
6 participants