Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
delete(n = 1) {
for (let i = 0; i < n; i += 1) {
const { $cursor } = this.selection;
const { from, to } = $cursor
? new Selection(this.selection.$from, this.rightPos.$from)
: this.selection;
this.apply(this.tr.replace(from, to, Slice.empty));
}
return this;
}
backspace(n = 1) {
for (let i = 0; i < n; i += 1) {
const { $cursor } = this.selection;
const { from, to } = $cursor
? new Selection(this.leftPos.$from, this.selection.$from)
: this.selection;
this.apply(this.tr.replace(from, to, Slice.empty));
}
return this;
}
selectRight(n = 1) {
const { $from } = this.state.selection;
let { $to } = this.state.selection;
for (let i = 0; i < n; i += 1) {
const $pos = this.state.doc.resolve($to.pos + 1);
$to = Selection.near($pos).$to;
}
return this.setSelection(new Selection($from, $to));
}
export const expandRange = (range: Range, doc: Node): Range => {
const $fromPos = doc.resolve(range.from);
const $toPos = doc.resolve(range.to);
const parentNode = findParentNode(node => node.isBlock)(
new Selection($fromPos, $toPos)
);
if (!parentNode) {
throw new Error(
`Parent node not found for position ${$fromPos.start}, ${$fromPos.end}`
);
}
return {
from: parentNode.start,
to: parentNode.start + parentNode.node.textContent.length
};
};