Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function insertNewLineAfterBlotAndTrim(quill, range: RangeStatic, deleteAmount = 1) {
const [line, offset] = quill.getLine(range.index);
const newBlot = new BlockBlot(BlockBlot.create(""));
const thisBlot = line;
const nextBlot = thisBlot.next;
newBlot.insertInto(quill.scroll, nextBlot);
// Now we need to clean up that extra newline.
const positionUpToPreviousNewline = range.index + line.length() - offset;
const deleteDelta = new Delta().retain(positionUpToPreviousNewline - deleteAmount).delete(deleteAmount);
quill.updateContents(deleteDelta, Emitter.sources.USER);
quill.setSelection(positionUpToPreviousNewline - deleteAmount, Emitter.sources.USER);
}
// Check that we don't have an embed blot at the end.
const lastBlot = this.quill.scroll.children.tail;
if (!(lastBlot instanceof ExternalEmbedBlot)) {
return;
}
// Filter out click events that aren't below the last item in the document.
const blotRect = (lastBlot.domNode as HTMLElement).getBoundingClientRect();
const bottomOfBlot = blotRect.bottom;
if (event.y <= bottomOfBlot) {
// The click not on the bottom section of the document.
return;
}
const newline = new BlockBlot(BlockBlot.create("\n"));
newline.insertInto(this.quill.scroll);
this.quill.update(Quill.sources.USER);
this.quill.setSelection(this.quill.scroll.length(), 0, Quill.sources.USER);
};
}
export function insertNewLineAtEndOfScroll(quill: Quill) {
const newLineBlot = new BlockBlot(BlockBlot.create(""));
quill.scroll.appendChild(newLineBlot);
quill.update(Quill.sources.USER);
quill.setSelection(quill.scroll.length(), 0);
}
export function insertNewLineAtStartOfScroll(quill: Quill) {
const newLineBlot = new BlockBlot(BlockBlot.create(""));
quill.scroll.insertBefore(newLineBlot, quill.scroll.children.head!);
quill.update(Quill.sources.USER);
quill.setSelection(0, 0);
}