-
Notifications
You must be signed in to change notification settings - Fork 48
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 bug not being able to disable H1 #247
Conversation
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.
Thanks for working on this @mortmoe! Generally looks good to me! Would you be able to squash your commits and remove changes to pnpm-lock? No changes to the lockfile should be necessary for this small tweak in MenuSelectHeading.tsx
.
src/controls/MenuSelectHeading.tsx
Outdated
@@ -200,6 +194,15 @@ export default function MenuSelectHeading({ | |||
return new Set(headingExtension?.options.levels ?? []); | |||
}, [editor]); | |||
|
|||
// We have to pass a level when running `can`, so this is just an arbitrary | |||
// one. And we have to check `currentLevel` to prevent all other heading |
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.
minor: say "an arbitrary one that is enabled" instead now
src/controls/MenuSelectHeading.tsx
Outdated
// https://github.com/sjdemartini/mui-tiptap/issues/197). | ||
const canSetHeading = | ||
enabledHeadingLevels.size > 0 && | ||
(currentLevel === [...enabledHeadingLevels][0] || |
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.
To make this more performant, can you pull out [...enabledHeadingLevels][0]
into a local variable instead of repeating it twice? And for getting the value, can you update this to use enabledHeadingLevels.values().next()
? The list spread approach is more expensive (e.g. see here for an explanation)
I'll do my best and try to fix this tomorrow. I'm a bit of a noob when it comes to working with GitHub, kind of my first time doing something like this 🤣 Googling like a maniac on how to get this tested locally, use Forks and all that 🤣 Fun to learn new stuff and probably long overdue anyway so I'll figure it out 👍 |
Build Removed build in package json
I think I've got it now. As I said, kind of new to this... I've tried several methods for using and testing this in my application:
I'm probably missing something obvious in 1. and 2. right? :) Anyway, I've tested the changes using method 3 and removed the build stuff now :) |
Thanks for cleaning up the commits and working through this! I'll make a couple tiny tweaks to the comments and variable definitions and merge this soon! 😄 In terms of testing out your change, I would recommend just testing with mui-tiptap/src/demo/useExtensions.ts Line 154 in 61d3f7a
If you want to test within your own project (which shouldn't be necessary for this specific bug fix, but maybe useful otherwise), I've found https://github.com/wclr/yalc to be a convenient option. |
Cool. Thanks for this, and thanks for the tips :) I did some testing with dev actually, just wanted to get it working locally to find a way to do it for other cases later on. I'll look into yalc next time :) |
Suggested fix for #228