Skip to content
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

Desktop: Fixes #10733: Fix not-yet-created images lost while editing with the Rich Text Editor #10734

Conversation

personalizedrefrigerator
Copy link
Collaborator

@personalizedrefrigerator personalizedrefrigerator commented Jul 10, 2024

Summary

This pull request adds support for converting "downloading" icons from HTML back into Markdown in the Rich Text Editor. At present, it's possible to edit notes with these placeholders if the placeholders were generated from images that link to non-existent resources.

This partially fixes #10733.

Important

This only fixes #10733 for Markdown notes. HTML notes still experience the issue.

Possible alternate solution: Disallow editing notes with "not downloaded" placeholders

At present, the Rich Text Editor prevents users from editing notes with linked resources that haven't been downloaded. However, images that point to resources that don't exist allow users to edit notes. Such resources might be created after a user manually deletes an attachment, edits the note in the Markdown editor, or due to a bug similar to the one mentioned here.

Completely disallowing users from editing notes with "not downloaded" placeholders would prevent users from editing notes that include deleted resources.

Testing plan

This pull request includes automated tests.

It has also been tested manually by:

  1. Creating a new note (in the Markdown editor) with the following content:
    ![testing](:/asdbfas781923847base213758909123)
    
    Test:
    
    <img alt="alt text here" src=":/asdbfas781923847base213758909123" title="title here &quot;" class="jop-noMdConv"/>
  2. Switching to the Rich Text Editor.
  3. Adding TEST to the end of the note.
  4. Backspacing TEST
  5. Switching back to the Markdown Editor and verifying that the note has roughly the same content it did originally (though perhaps with a trailing &nbsp; ).

Comment on lines +11 to +12
<div class="not-loaded-resource not-loaded-image-resource resource-status-notDownloaded" data-resource-id="a1test2a1test2a1test2a1test22347" data-original-before=" " data-original-after=" class=&quot;jop-noMdConv&quot;/" contenteditable="false"><img src="data:image/svg+xml;utf8,
&Tab;&Tab;&lt;svg width=&quot;1700&quot; height=&quot;1536&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • To-do (optional/nonblocking?): Debug: Why is class=&quot;jop-noMdConv&quot; added to data-original-after?

Comment on lines +156 to +167
const htmlBefore = node.getAttribute('data-original-before') || '';
const htmlAfter = node.getAttribute('data-original-after') || '';
const isHtml = htmlBefore || htmlAfter;
const resourceId = node.getAttribute('data-resource-id');
if (isHtml) {
const attrs = [
htmlBefore.trim(),
`src=":/${resourceId}"`,
htmlAfter.trim(),
].filter(a => !!a);

return `<img ${attrs.join(' ')}>`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Optional: Try to reduce future code duplication: Pass a function through options to do part of the conversion? Alternatively, add to utils.

At present, much of this logic will need to be duplicated when fixing #10733 for HTML notes.

@laurent22
Copy link
Owner

Thanks for fixing this!

Optional: Try to reduce future code duplication: Pass a function through options to do part of the conversion? Alternatively, add to utils. At present, much of this logic will need to be duplicated when fixing #10733 for HTML notes.

If we fix this for HTML notes we can refactor at that time

@laurent22 laurent22 merged commit 624bfd9 into laurent22:dev Jul 16, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rich text editor: Markup with non-existent resource SRCs is broken
2 participants