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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -95,7 +95,7 @@ export default function openEditDialog(editor: any, markupToHtml: any, dispatchD
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
onSubmit: async (dialogApi: any) => {
const newSource = newBlockSource(dialogApi.getData().languageInput, dialogApi.getData().codeTextArea, source);
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.

const result = await markupToHtml.current(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, md, { bodyOnly: true });

// markupToHtml will return the complete editable HTML, but we only
Expand Down