fixed offset problems with toggleList

This commit is contained in:
Chrissi2812 2019-05-20 12:05:11 +02:00
parent a24fdac9f7
commit ac89ca404a
No known key found for this signature in database
GPG Key ID: B4B82C7E618271DA

View File

@ -11,17 +11,19 @@ export default function toggleList(listType) {
const wrap = wrapInList(listType)
const { $from, $to } = state.selection
const range = $from.blockRange($to)
const depthOffset = range.depth > 1 ? ((range.depth + 1) % 2) : 0
if (!range) {
return false
}
if (range.depth >= 1 && $from.node(range.depth).type === listType) {
if (range.depth >= 1 && $from.node(range.depth - depthOffset).type === listType) {
return lift(state, dispatch)
}
if (range.depth >= 1 && isList($from.node(range.depth), schema)) {
if (range.depth >= 1 && isList($from.node(range.depth - depthOffset), schema)) {
const { tr } = state
tr.setNodeMarkup(range.start - 1, listType)
const $insert = state.doc.resolve(range.start - depthOffset)
tr.setNodeMarkup(range.start - (1 + depthOffset) - $insert.parentOffset, listType)
if (dispatch) dispatch(tr)
return false
}