Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// This is at the top of an existing list item
if (
range.depth >= 2 &&
$from.node(range.depth - 1).type.compatibleContent(nodeType) &&
range.startIndex === 0
) {
// Don't do anything if this is the top of the list
if ($from.index(range.depth - 1) == 0) {
return tr;
}
let $insert = tr.doc.resolve(range.start - 2);
outerRange = new NodeRange($insert, $insert, range.depth);
if (range.endIndex < range.parent.childCount) {
range = new NodeRange(
$from,
tr.doc.resolve($to.end(range.depth)),
range.depth,
);
}
doJoin = true;
}
const wrappers = findWrapping(outerRange, nodeType, attrs, range);
return doWrapInList(
tr,
range,
wrappers,
doJoin,
nodeType,
);
}
endOfList = range.$to.end(range.depth);
if (end < endOfList) {
// There are siblings after the lifted items, which must become
// children of the last item
tr.step(
new ReplaceAroundStep(
end - 1,
endOfList,
end,
endOfList,
new Slice(Fragment.from(itemType.create(undefined, range.parent.copy())), 1, 0),
1,
true
)
);
range = new NodeRange(
tr.doc.resolve(range.$from.pos),
tr.doc.resolve(endOfList),
range.depth
);
}
dispatch(tr.lift(range, liftTarget(range)!).scrollIntoView());
return true;
}
}
if (!range) {
return tr;
}
// This is at the top of an existing list item
if (
range.depth >= 2 &&
$from.node(range.depth - 1).type.compatibleContent(nodeType) &&
range.startIndex === 0
) {
// Don't do anything if this is the top of the list
if ($from.index(range.depth - 1) == 0) {
return tr;
}
let $insert = tr.doc.resolve(range.start - 2);
outerRange = new NodeRange($insert, $insert, range.depth);
if (range.endIndex < range.parent.childCount) {
range = new NodeRange(
$from,
tr.doc.resolve($to.end(range.depth)),
range.depth,
);
}
doJoin = true;
}
const wrappers = findWrapping(outerRange, nodeType, attrs, range);
return doWrapInList(
tr,
range,
wrappers,
doJoin,
nodeType,
if (end < endOfList) {
// There are siblings after the lifted items, which must become
// children of the last item
const frag = Fragment.from(itemType.create(null, range.parent.copy()));
const slice = new Slice(frag, 1, 0);
const step = new ReplaceAroundStep(
end - 1,
endOfList,
end,
endOfList,
slice,
1,
true,
);
tr = tr.step(step);
range = new NodeRange(
tr.doc.resolve(range.$from.pos),
tr.doc.resolve(endOfList),
range.depth,
);
}
return tr.lift(range, liftTarget(range));
}