fix: nodeInputRule() support for group match (#1574)
* Fix: nodeInputRule() support for group match Fixes in nodeInputRule() - add support for "first group match, if any" similar to https://prosemirror.net/docs/ref/#inputrules - fix issue where rewriting includes extra unnecessary character from the match * Insert last typed in nodeInputRule group match
This commit is contained in:
@@ -8,8 +8,24 @@ export default function (regexp: RegExp, type: NodeType, getAttributes?: (match:
|
|||||||
: getAttributes
|
: getAttributes
|
||||||
const { tr } = state
|
const { tr } = state
|
||||||
|
|
||||||
if (match[0]) {
|
if (match[1]) {
|
||||||
tr.replaceWith(start - 1, end, type.create(attributes))
|
const offset = match[0].lastIndexOf(match[1])
|
||||||
|
let matchStart = start + offset
|
||||||
|
if (matchStart > end) {
|
||||||
|
matchStart = end
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
end = matchStart + match[1].length
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert last typed character
|
||||||
|
const lastChar = match[0][match[0].length - 1]
|
||||||
|
tr.insertText(lastChar, start + match[0].length - 1)
|
||||||
|
|
||||||
|
// insert node from input rule
|
||||||
|
tr.replaceWith(matchStart, end, type.create(attributes))
|
||||||
|
} else if (match[0]) {
|
||||||
|
tr.replaceWith(start, end, type.create(attributes))
|
||||||
}
|
}
|
||||||
|
|
||||||
return tr
|
return tr
|
||||||
|
|||||||
Reference in New Issue
Block a user