fix: add way to cancel inputrules and pasterules (#2368)

Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
This commit is contained in:
Philipp Kühn
2022-01-10 14:43:56 +01:00
committed by GitHub
parent 5144a6cd1b
commit 669efd00e9
10 changed files with 112 additions and 86 deletions

View File

@@ -24,7 +24,7 @@ export function markInputRule(config: {
const attributes = callOrReturn(config.getAttributes, undefined, match)
if (attributes === false || attributes === null) {
return
return null
}
const { tr } = state
@@ -64,6 +64,8 @@ export function markInputRule(config: {
tr.removeStoredMark(config.type)
}
return tr
},
})
}

View File

@@ -45,6 +45,8 @@ export function nodeInputRule(config: {
} else if (match[0]) {
tr.replaceWith(start, end, config.type.create(attributes))
}
return tr
},
})
}

View File

@@ -29,7 +29,11 @@ export function textInputRule(config: {
}
}
state.tr.insertText(insert, start, end)
const { tr } = state
tr.insertText(insert, start, end)
return tr
},
})
}

View File

@@ -29,9 +29,12 @@ export function textblockTypeInputRule(config: {
return null
}
state.tr
.delete(range.from, range.to)
const { tr } = state
tr.delete(range.from, range.to)
.setBlockType(range.from, range.from, config.type, attributes)
return tr
},
})
}

View File

@@ -54,6 +54,8 @@ export function wrappingInputRule(config: {
) {
tr.join(range.from - 1)
}
return tr
},
})
}