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 removal of textStyle mark when any style resets #1465

Merged
merged 1 commit into from
Jun 14, 2021

Conversation

bttger
Copy link
Contributor

@bttger bttger commented Jun 14, 2021

I built some extensions based on the textStyle extension but whenever I reset a style/attribute, the whole textStyle mark gets removed when there are still other styles defined in the mark.

I built some extensions based on the textStyle extension but whenever I reset a style/attribute, the whole textStyle mark gets removed when there are still other styles defined in the mark.
@philippkuehn
Copy link
Contributor

removeEmptyTextStyle should prevent rendering an empty style tag (style="") so I can’t merge this.

But I can’t understand the issue right now. Could you please create an issue + codesandbox for it?

@bttger
Copy link
Contributor Author

bttger commented Jun 14, 2021

removeEmptyTextStyle should prevent rendering an empty style tag (style="") so I can’t merge this.

Yes, my fix does exactly that. I also used the fontFamily extension from the tiptap/core and when calling the unsetFontFamily() method, it removes the styles tag even though there are still other extensions (built exactly like fontFamily) that have set a property on the styles object.

This is an example style object:
{fontFamily: "Ubuntu, sans-serif", fontSize: "xx-large", fontColor: "#FFFFFFFF", lineHeight: "1", underline: "underline"}

When you unset one of these attributes (e.g. to null like in the fontFamily extension), the Object.entries(attributes).every(([, value]) => !!value) operation returns false:

const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
if (hasStyles) {
    return true
}

I believe that this is not intentional and that we should use the some() method to check if there is at least one style set on the mark.

@philippkuehn
Copy link
Contributor

Ah sorry, you are absolutely right!

@philippkuehn philippkuehn reopened this Jun 14, 2021
@philippkuehn philippkuehn merged commit fbf4422 into ueberdosis:main Jun 14, 2021
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