mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 11:09:01 +08:00
fixed offset problems with toggleList
This commit is contained in:
parent
a24fdac9f7
commit
ac89ca404a
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user