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

Fix: Ensure block transformation works in the example #5803

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

aberllin
Copy link
Contributor

@aberllin aberllin commented Feb 5, 2025

Description
I noticed that the current example for toggling a code block using the backtick key doesn't work as expected. The issue occurs because Editor.nodes() can return text nodes instead of block elements, causingTransforms.setNodes() to fail.

To fix this, I added an extra check using Element.isElement(n), ensuring that only block elements are transformed.

Issue
Slate docs - Applying Custom Formatting

Example
Before the fix:
Pressing the backtick key sometimes fails to toggle a code block due to Transforms.setNodes() being applied to text nodes - demo.

After the fix:
The backtick key now correctly toggles a code block, as the logic ensures only block elements are transformed - demo

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

I noticed that the current example for toggling a code block using the backtick (`) key doesn't work as expected. The issue occurs because `Editor.nodes()` can return text nodes instead of block elements, causing`Transforms.setNodes()` to fail.

To fix this, I added an extra check using `Element.isElement(n)`, ensuring that only block elements are transformed.
Copy link

changeset-bot bot commented Feb 5, 2025

⚠️ No Changeset found

Latest commit: b0f3ea5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dylans dylans merged commit 7a8ab18 into ianstormtaylor:main Feb 10, 2025
4 of 11 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.

2 participants