ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
27.55k stars 2.29k forks source link

[Bug]: Alignment Styles Not Overridden or Unchanged for Pasted Content using React #5755

Closed Renjith-SB closed 1 week ago

Renjith-SB commented 3 weeks ago

Affected Packages

extension-text-align

Version(s)

1.32.2

Bug Description

Alignment Styles Not Overridden or Unchanged for Pasted Content using React Description When pasting content that contains alignment styles (e.g., text-align: center;), attempting to change the alignment afterward using the extended TextAlign plugin with the setTextAlign command does not override the existing alignment style or has no effect on the pasted content. This affects the user experience when modifying the alignment of formatted text.

Steps to Reproduce

image

Actual Behavior

Code Example Below is an example of how the TextAlign plugin is extended and the setTextAlign command is used:


import { TextAlign } from '@tiptap/extension-text-align';

const CustomTextAlign = TextAlign.extend({
  addCommands() {
    return {
      setTextAlign: alignment => ({ commands }) => {
        const resetAndUpdate = this.options.types.every(type => 
          (commands.resetAttributes(type, 'style') || commands.resetAttributes(type, 'textAlign')) &&
          commands.updateAttributes(type, { textAlign: alignment })
        );
        return resetAndUpdate;
      }
    };
  }
});

In this implementation:

Environment:

Browser Used

Chrome

Code Example URL

No response

Expected Behavior

The alignment of the pasted content should be overridden by the new alignment selected by the user via the setTextAlign command.

Additional Context (Optional)

This issue occurs consistently when content with inline or block-level styles is pasted into the editor. Users expect the setTextAlign command to override any existing alignment styles.

Dependency Updates

GSKarthik369 commented 3 weeks ago

Facing similar issue. Any solution on this will be great.

guarmo commented 1 week ago

The version you're using is deprecated, I would recommend updating to the latest Tiptap version.

Renjith-SB commented 2 days ago

The version you're using is deprecated, I would recommend updating to the latest Tiptap version.

Thank you for your response. I tried switching to the new version, but it’s not working.

Here is the pasted content:

text-align: justify; margin: 0px 0px 15px; padding: 0px; text-align: justify; color: rgb(0, 0, 0); font-family: "Open Sans", Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;

As you can see, it has multiple text-align styles. The setTextAlign command only affects the first text-align style.