Hello ProseMirror community,
I’m trying to fix a bug in the Nextcloud Text app: its ListItem node defines an input rule /^\s*([-+*])\s[^\s[]$/
to start a list item, which results in the first key after /^\s*([-+*])\s
being eaten. That’s rather annoying.
My idea was to catch the entered key (as a regex match) and insert it as text content of the node in toDOM
. But apparently that doesn’t work as expected.
Catching the key works as expected:
export default class ListItem extends TiptapListItem {
[...]
get schema() {
return {
attrs: {
done: {
default: false,
},
type: {
default: TYPES.BULLET,
},
appendix: {
default: '',
},
},
[...]
}
}
[...]
inputRules({ type }) {
return [
[...],
wrappingInputRule(/^\s*([-+*])\s([^\s[])$/, type, (match) => {
return { appendix: match[2] }
}),
]
}
With this code, node.atts.appendix
contains the single character at the end of the regex (e.g. t
if I entered * t
).
But I fail to add node.attrs.appendix
(match[2]
from the input rule) as content in toDOM()
:
get schema() {
return {
[...],
toDOM: node => {
if (node.attrs.type === TYPES.BULLET) {
return [
'li',
{ contentEditable: true },
`$(node.attrs.appendix)`,
]
}
},
[...]
}
}
With the code above, when entering * t
, I indeed get a list item with t
as content, but the cursor immediately jumps up one line and everything behaves rather weird.
I’m pretty new to prosemirror and still struggeling to find my way through. Any hint about what I’m doing wrong would be highly appreciated
Cheers jonas