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/blockquote commands #5746

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

guanriyue
Copy link

Changes Overview

Fix the issues with setBlockquote and unsetBlockquote commands.

Implementation Approach

Tiptap checks isNodeActive by searching upwards from the current position, and based on the result, it executes either wrapIn or lift. However, ProseMirror's wrapIn and lift only evaluate the current blockRange, which can cause the command to not function as expected.

To address this, add a findWrappingUntil helper, which will search upwards until it finds a valid wrapping position. This will resolve issue #3743.

Additionally, add a nodeType check when retrieving blockRange in the lift command, which will resolve issue #4434.

Testing Done

In the example default editor, a disabled attribute was added to the blockquote action button. This will disable the button when the action cannot be performed. The id attribute was also added for better Cypress testing.

Three test cases were added:

  1. When the cursor is on the first child element of a list item, toggleBlockquote will wrap the entire list.
  2. When the cursor is on the second child element of a list item, toggleBlockquote will wrap only the second element.
  3. For a list already wrapped in a blockquote, when the cursor is on the first child element of a list item, toggleBlockquote will remove the blockquote wrapping without altering the list.

Verification Steps

Visit the default editor page or run the Cypress tests.

Additional Notes

It seems we should directly modify commands.wrapIn instead of changing setBlockquote in the blockquote extension. The range of checks in ProseMirror.wrapIn and tiptap.isNodeActive are inconsistent, which may be the core issue.

On the other hand, the situation with commands.lift is the opposite, as lift has a specific node type. We must search upwards from the current position to find the required type.

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

…n the cursor is in a `listItem`, setting or unsetting `blockquote` is allowed.
…is on the first paragraph of a `listItem`, setting `blockquote` should be allowed, and the `blockquote` will wrap the entire list.
…en the cursor is on the first element of a list item, setting `blockquote` will wrap the entire list; and when the cursor is on the second element of a list item, setting `blockquote` will only wrap the second element.
…or.lift` leads to incorrect modifications.
Copy link

changeset-bot bot commented Oct 22, 2024

⚠️ No Changeset found

Latest commit: acdcdbf

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

Copy link

netlify bot commented Oct 22, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit acdcdbf
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/6717234085543600083f1b10
😎 Deploy Preview https://deploy-preview-5746--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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.

1 participant