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: Resolves #10315: Do not trim markdown upon saving in rich text #10321

Merged
merged 1 commit into from Apr 17, 2024

Conversation

chaNcharge
Copy link
Contributor

This fixes #10315 where markdown was erroneously trimming leading and trailing whitespace. There are some cases where users would like to keep the markdown as is without any changes, as shown in cwesson/joplin-plugin-typograms#1. This PR removes the trim string method in the openEditDialog.tsx component. I am not entirely sure why it is in there in the first place nor can I think of a reason why markdown would need to be trimmed if the user wrote markdown with trailing whitespace in our use case, so I removed it.

const md = `${newSource.openCharacters}${newSource.content.trim()}${newSource.closeCharacters}`;
const md = `${newSource.openCharacters}${newSource.content}${newSource.closeCharacters}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not entirely sure why it is in there in the first place nor can I think of a reason why markdown would need to be trimmed if the user wrote markdown with trailing whitespace in our use case, so I removed it.

It looks like this was added in 84c3ef1#diff-4eba09d3f5fecc9c57315952b11b3ab68a356d30e87314712467c7e8972ccaa1R232 (the same commit that added the rich text editor).

In the past, we've had bugs related to extra lines being added to the end of code and math regions when saving content in the Rich Text editor (e.g. #6822, #9589). Perhaps this was an attempted/partial fix for one of those issues?

I removed it.

That should be fine!

As there aren't any automated tests for this, I've manually verified that:

  • This doesn't cause additional leading/trailing newlines to be added to math blocks after saving changes made by the editor.
  • This doesn't cause additional leading trailing newlines to a multi-line JavaScript codeblock when saving code editor changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great. I've also had a quick look at the issues you linked and tested those issues and verified that those issues are separate from the one this PR is aiming to fix, as the code block's onSubmit callback is not called when changing editors.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes there was a problem before where newlines kept being added each time the dialog was closed, but maybe it's no longer happening. Let's merge for now and see if anyone finds any issue.

@laurent22 laurent22 merged commit 74cda4e into laurent22:dev Apr 17, 2024
10 checks passed
@chaNcharge chaNcharge deleted the bugfix/no-destroy-md branch April 17, 2024 20:22
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: Editing code blocks removes leading whitespace
3 participants