Skip to content

Desktop: Fixes #9588: Removed download button on mermaid diagrams in rich text editor #12055

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 6 commits into
base: dev
Choose a base branch
from

Conversation

outrodani
Copy link

This PR fixes #9588 by removing the download button while hovering over a mermaid diagram in the rich text editor.

I simply added a verification that checks if the tox-tinymce class is used. If that is the case, the exportButtonMarkup constant will simply be an empty string, resulting in the download button not being visible. Since this class is only found in the rich text editor, the download button will remain visible and functional in the markdown editor.

Video.sem.titulo.-.Feito.com.Clipchamp.mp4

outrodani and others added 2 commits March 26, 2025 22:53
… work

Added an additional verification that will only allow the mermaid
diagram download button to appear if the user is using the markdown
editor. It uses the document object, which represents the
loaded html page, and the function querySelector to look for the
first instance of use of the tox-tinymce class, exclusively used in
the rich text editor. If the return value of this verification is
not null, the constant exportButtonMarkup will simply be an empty
string, instead of calling the exportGraphButton function. This
way, the download button will not be visible in the rich text
editor.
Copy link
Contributor

github-actions bot commented Apr 4, 2025

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@outrodani
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 4, 2025
@@ -62,7 +62,7 @@ export default {
return self.renderToken(tokens, idx, options, env, self);
};

const exportButtonMarkup = isDesktop(ruleOptions.platformName) ? exportGraphButton(ruleOptions) : '';
const exportButtonMarkup = (isDesktop(ruleOptions.platformName) && !document.querySelector('.tox-tinymce')) ? exportGraphButton(ruleOptions) : '';
Copy link
Owner

Choose a reason for hiding this comment

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

We shouldn't have references to the document here as there's no guarantee it's always available. As you see we normally pass arguments, such as ruleOptions.platformName to inform how things should work within the package. So it should be a similar solution here

Copy link
Author

Choose a reason for hiding this comment

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

My first approach was actually to alter RuleOptions so that it could pass the editor as an argument, however I did not find a way to detect which editor was currently in use. Since i didn't find much success with that approach I decided to go for the change you saw...

Copy link
Owner

Choose a reason for hiding this comment

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

Setting.value('editor.codeView') would tell you that

@personalizedrefrigerator
Copy link
Collaborator

Thank you for working on this!

For reference, I'm linking to a commit that takes an alternate approach that might fix this if we do eventually want to support the download button in the Rich Text Editor. (If I recall correctly, there was an issue with the linked commit (e.g. right-click menus opened with the keyboard didn't work?)).

@@ -1,4 +1,5 @@
import { RuleOptions } from '../../MdToHtml';
import Setting from '../../../lib/models/Setting';
Copy link
Owner

Choose a reason for hiding this comment

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

Unfortunately we also can't have this here because that introduces a dependency to settings which may or may not have been initialized at that point (or which may be irrelevant in some contexts). You've also created a circular loop so the project will randomly not compile.

I assume this is more challenging to fix than it seems. Whenever I want to change something in here I have to change 5 or 6 files to pass around options.

Copy link
Author

Choose a reason for hiding this comment

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

Oh I see. I was finding it weird because i could run Joplin with the fix on my machine however the checks kept failing and I wasn't being able to find the cause through the logs.

@personalizedrefrigerator
Copy link
Collaborator

Note: #9588 should now be partially fixed by #12076 (the download button now shows a menu, but it doesn't have download options).

@outrodani
Copy link
Author

The purpose of this PR was to remove the download button because it wasn't functional. However, now that it does show a menu (even if without download options), is there still a reason to remove the button?

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: Mermaid diagram download button doesn't work
3 participants