-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Hash character with the suggestion utility conflicts with heading Markdown shortcut #2570
Comments
FYI, as an ugly workaround, I'm handling the const { state, view } = props.editor
if (state.plugins.length > 0) {
const restOfPlugins: Plugin[] = []
const suggestionPlugins: Plugin[] = []
state.plugins.forEach((plugin) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: The `Plugin` type does not include `key`
if ((plugin.key as string).includes('Suggestion')) {
suggestionPlugins.push(plugin)
} else {
restOfPlugins.push(plugin)
}
})
view.updateState(
state.reconfigure({
plugins: [...suggestionPlugins, ...restOfPlugins],
}),
)
} Would love it if something akin to the extension priorities was possible for these ProseMirror plugins, so we can pick the ones we need to have a higher priority than the built-in ones, like the input rules. |
I also encountered this problem, But I don't see how to use this solution. |
@cmcQDGCS You have to put that code in the |
@rfgamaral Thank you for your reply, No wonder I can't understand it. I use Vue. I'll study it again |
It shouldn't matter what you use... In the same place you pass the extensions to use, handle the |
@rfgamaral owowow!!I know what you mean! |
@cmcQDGCS We have multiple mention-like extensions, and we named them all with "suggestion" in the name (we don't use the official mention extension). You have to adapt that part to your needs. It seems you're using the official one, so changing |
@rfgamaral I tried, but I still haven't solved it...I don't know why. |
Start explaining exactly what you're doing, and the problem you're having? Try to create a CodeSandbox minimal example, and explain the issue you're having. |
@rfgamaral |
Tried to take a look, but I can't figure out what's wrong... Maybe you were right, and Vue works different on how it initializes the editor, which is having an impact on this. Maybe @bdbch can provide more insight here. Sorry, I'm a React developer, I barely know anything about Vue. |
Thank you very much for your help. I'll go and have a deep understanding |
@rfgamaral does the priority have any effect on that issue? |
I don't think it does because the problem here lies in the ProseMirror plugins priority, and not the Tiptap extensions priority (which are 2 different things). As I've suggested in the OP, I think we need a way to override the priority for ProseMirror plugins, akin to the Extensions |
@rfgamaral pointed it out well here. Right now you'd have to fallback to a dirty solution. I think a way to override the priorities of loaded ProseMirror plugins would be a neat way to solve this issue. @Cuimc I'll take a look at your sandbox but have to say I'm also not a primary Vue developer. |
This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days |
This is really painful. Is there any easier workaround for this? |
Hi there, just ran into this now. Here's how I fixed this on my end. I'm using Vue tiptap but I think this should work for everyone. Here's some context so you know if this applies to you as well.
What I did is extend the heading extension, modify the input rule to only support spaces after the Heading.extend({
addInputRules() {
return this.options.levels.map((level) => {
return textblockTypeInputRule({
- find: new RegExp(`^(#{1,${level}})\\s$`),
+ find: new RegExp(`^(#{1,${level}}) $`),
type: this.type,
getAttributes: {
level,
},
})
})
},
}) |
@jaggy The cleanest solution here, I guess this issue is resolved. I put more doc for the rookies import { useEditor, textblockTypeInputRule } from '@tiptap/react';
// ...
useEditor({
extensions: [
Heading.extend({
addInputRules() {
return this.options.levels.map((level: number) => {
return textblockTypeInputRule({
find: new RegExp(`^(#{1,${level}}) $`),
type: this.type,
getAttributes: {
level,
},
})
})
},
}),
StarterKit.configure({
heading: false,
})
]
}) |
What’s the bug you are facing?
When using the
#
as thechar
in the Suggestion utility, this conflicts with the heading Markdown shortcut IF it's the first character in an empty paragraph. Instead of adding the selected suggestion, the paragraph is converted to a heading instead.How can we reproduce the bug on our side?
#
into the editor as the first character in an empty paragraphCan you provide a CodeSandbox?
What did you expect to happen?
The selected suggestion from the dropdown should've been added to the editor.
Anything to add? (optional)
A few observations:
handleKeyDown
will take precedence over other extensions/pluginshandleKeyDown
event handlers, that's why we have the behavior here described.priority
property (similar to what we have for extensions) so that we can have certain plugins being handled before the input rules plugin.Did you update your dependencies?
Are you sponsoring us?
The text was updated successfully, but these errors were encountered: