Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const findSpecialNodeBefore = ($pos: ResolvedPos, tr: Transaction, matchers: NodeMatch[]) => {
if (nodeNameMatchesList($pos.nodeBefore, matchers)) {
return $pos.pos - 1;
}
if ($pos.pos === 0) {
return;
}
const { parentOffset } = $pos;
if (parentOffset === 0) {
const { nodeBefore } = tr.doc.resolve($pos.pos - 1);
if (nodeBefore && nodeNameMatchesList(nodeBefore.firstChild, matchers)) {
return $pos.pos - 2;
}
}
return;
};
export const findSpecialNodeBefore = ($pos: ResolvedPos, tr: Transaction, matchers: NodeMatch[]) => {
if (nodeNameMatchesList($pos.nodeBefore, matchers)) {
return $pos.pos - 1;
}
if ($pos.pos === 0) {
return;
}
const { parentOffset } = $pos;
if (parentOffset === 0) {
const { nodeBefore } = tr.doc.resolve($pos.pos - 1);
if (nodeBefore && nodeNameMatchesList(nodeBefore.firstChild, matchers)) {
return $pos.pos - 2;
}
}
export const findSpecialNodeAfter = ($pos: ResolvedPos, tr: Transaction, matchers: NodeMatch[]) => {
if (nodeNameMatchesList($pos.nodeAfter, matchers)) {
return $pos.pos + 1;
}
const { parentOffset, parent } = $pos;
const docSize = tr.doc.nodeSize - 2;
if (parentOffset === parent.content.size && $pos.pos + 1 < docSize - 2) {
const { nodeAfter } = tr.doc.resolve($pos.pos + 1);
if (nodeAfter && nodeNameMatchesList(nodeAfter.firstChild, matchers)) {
return $pos.pos + 2;
}
}
return;
};
tr.doc.resolve(tr.mapping.map($from.pos - $from.nodeBefore.nodeSize)),
);
tr.setSelection(newSelection);
dispatch(tr);
pluginState.endDelete(newSelection);
return true;
}
/**
* This block caters for highlighting the defined nodes when a selection has been made
*/
if (
isTextSelection(selection) &&
selection.$cursor === null &&
$from.nodeAfter &&
nodeNameMatchesList($from.nodeBefore, ensureNodeDeletion)
) {
event.preventDefault();
dispatch(state.tr.deleteSelection());
return true;
}
return false;
};
export const findSpecialNodeAfter = ($pos: ResolvedPos, tr: Transaction, matchers: NodeMatch[]) => {
if (nodeNameMatchesList($pos.nodeAfter, matchers)) {
return $pos.pos + 1;
}
const { parentOffset, parent } = $pos;
const docSize = tr.doc.nodeSize - 2;
if (parentOffset === parent.content.size && $pos.pos + 1 < docSize - 2) {
const { nodeAfter } = tr.doc.resolve($pos.pos + 1);
if (nodeAfter && nodeNameMatchesList(nodeAfter.firstChild, matchers)) {
return $pos.pos + 2;
}
}
return;
};