diff --git a/packages/tiptap-commands/src/commands/toggleList.js b/packages/tiptap-commands/src/commands/toggleList.js index ad7fde5c7..0a7a22d74 100644 --- a/packages/tiptap-commands/src/commands/toggleList.js +++ b/packages/tiptap-commands/src/commands/toggleList.js @@ -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 }