Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tr.doc.nodesBetween(startPos, endPos, (node, pos) => {
if (
node.isText || // Text node
(node.isTextblock && !node.textContent) // Empty paragraph
) {
const res = tr.doc.resolve(tr.mapping.map(pos));
const sel = new NodeSelection(res);
const range = nullthrows(sel.$from.blockRange(sel.$to));
const target = liftTarget(range);
if (target || target === 0) {
tr = tr.lift(range, target);
}
}
});
export function liftEmptyBlock(state, dispatch) {
let {$cursor} = state.selection
if (!$cursor || $cursor.parent.content.size) return false
if ($cursor.depth > 1 && $cursor.after() != $cursor.end(-1)) {
let before = $cursor.before()
if (canSplit(state.doc, before)) {
if (dispatch) dispatch(state.tr.split(before).scrollIntoView())
return true
}
}
let range = $cursor.blockRange(), target = range && liftTarget(range)
if (target == null) return false
if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView())
return true
}
export function liftBlockquote(state: EditorState, dispatch: Dispatch | null) {
const range = getRangeForType(state, state.schema.nodes.blockquote)
if (!range) return false
const target = liftTarget(range)
if (!target) return false
if (dispatch) {
dispatch(state.tr.lift(range, target)) //dont lift lists
}
return true
}
match.matchType(conn[0] || after.type).validEnd) {
if (dispatch) {
let end = $cut.pos + after.nodeSize, wrap = Fragment.empty
for (let i = conn.length - 1; i >= 0; i--)
wrap = Fragment.from(conn[i].create(null, wrap))
wrap = Fragment.from(before.copy(wrap))
let tr = state.tr.step(new ReplaceAroundStep($cut.pos - 1, end, $cut.pos, end, new Slice(wrap, 1, 0), conn.length, true))
let joinAt = end + 2 * conn.length
if (canJoin(tr.doc, joinAt)) tr.join(joinAt)
dispatch(tr.scrollIntoView())
}
return true
}
let selAfter = Selection.findFrom($cut, 1)
let range = selAfter && selAfter.$from.blockRange(selAfter.$to), target = range && liftTarget(range)
if (target != null && target >= $cut.depth) {
if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView())
return true
}
return false
}
export function liftBlockquote(state: EditorState, dispatch: Function) {
const range = getRangeForType(state, state.schema.nodes.blockquote)
if (!range) return false
const target = liftTarget(range)
if (!target) return false
if (dispatch) {
dispatch(state.tr.lift(range, target)) //dont lift lists
}
return true
}
export default function lift(
tr: Transform,
): Transform {
const {selection} = tr;
if (!selection) {
return tr;
}
const $from = selection.$from;
const $to = selection.$to;
const range = $from.blockRange($to);
if (range) {
const target = liftTarget(range);
if (target !== null) {
tr = tr.lift(range, target);
}
}
return tr;
}
export function lift(state, dispatch) {
let {$from, $to} = state.selection
let range = $from.blockRange($to), target = range && liftTarget(range)
if (target == null) return false
if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView())
return true
}
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;
}
}
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));
}