Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ export const getParentBlockInfo = (doc: Node, beforePos: number) => {

// get start pos of parent
const parentBeforePos = $pos.posAtIndex(
$pos.index($pos.depth - 1),
$pos.depth - 1,
// TODO: This works for blockContainer nodes as we need to traverse 2
// nesting levels due to the blockGroup in between. However, that's not the
// case for columns.
$pos.index($pos.depth - 2),
$pos.depth - 2,
);

const parentBlockInfo = getBlockInfoFromResolvedPos(
Expand Down Expand Up @@ -50,6 +53,27 @@ export const getPrevBlockInfo = (doc: Node, beforePos: number) => {
return prevBlockInfo;
};

/**
* Returns the block info from the sibling block after (below) the given block,
* or undefined if the given block is the last sibling.
*/
export const getNextBlockInfo = (doc: Node, beforePos: number) => {
const $pos = doc.resolve(beforePos);

const indexInParent = $pos.index();

if (indexInParent === $pos.node().childCount - 1) {
return undefined;
}

const nextBlockBeforePos = $pos.posAtIndex(indexInParent + 1);

const nextBlockInfo = getBlockInfoFromResolvedPos(
doc.resolve(nextBlockBeforePos),
);
return nextBlockInfo;
};

/**
* If a block has children like this:
* A
Expand Down
Loading
Loading