-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[lexical-markdown] Bug fix: Prevent transform from removing nodes if the replace function returns false #7564
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Seems like one of the test suites is timing out but it's unrelated to this change? |
Likely, I will restart it. Do you plan to write some additional tests or make any other changes before review? It is still marked WIP. |
I was trying to write a test, but I'm not sure how to set this up without changing some of the transformers, so I won't unless someone thinks it's required and can guide me on how to set a up a test for this. If the current tests pass I'll leave it as is. |
You should be able to write a unit test which wouldn't require changing other code, there's at least one transformer defined in the unit tests for the markdown package to test something that can't be reproduced in the playground. |
Ok I added a couple of tests, the first of which fails for the old behaviour. I added one for the normal header transforms to also avoid regressions with that and confirm my test was actually testing the right thing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tentatively looks good, other than this typo in the tests. Will wait to see the result of the full test run.
@@ -213,6 +223,18 @@ const CODE_TAG_COUNTER_EXAMPLE: MultilineElementTransformer = { | |||
type: 'multiline-element', | |||
}; | |||
|
|||
export const CENCELED_HEADING_REPLACE_EXAMPLE: ElementTransformer = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const CENCELED_HEADING_REPLACE_EXAMPLE: ElementTransformer = { | |
export const CANCELED_HEADING_REPLACE_EXAMPLE: ElementTransformer = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops, will fix that, thanks!
], | ||
}); | ||
|
||
registerMarkdownShortcuts(editor, [CENCELED_HEADING_REPLACE_EXAMPLE]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registerMarkdownShortcuts(editor, [CENCELED_HEADING_REPLACE_EXAMPLE]); | |
registerMarkdownShortcuts(editor, [CANCELED_HEADING_REPLACE_EXAMPLE]); |
Description
Currently if you return
false
from a Markdown transformer replace function, the expectation is that the transform will be cancelled, however the matched nodes are still being modified (removed) because the leading node gets removed before checking the return value of the replace function. This prevents implementing some functionality, such as not turning headers into numbered lists, and could cause other issues since when the next transform runs it won't have the leading node anymore.Describe the changes in this pull request
I tried to keep it simple and just moved the
remove
function so that it runs only if the replace function does not return false. All tests pass.Closes #7563
Test plan
Ran all the unit and e2e tests and they all pass.
Before and after video
https://share.cleanshot.com/JYWVlb4d