Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function handleBackspace(range, context) {
if (handleTables(range, this.quill)) return true; // handle tables
if (range.index === 0) return;
let [line, ] = this.quill.getLine(range.index);
let formats = {};
if (context.offset === 0) {
let curFormats = line.formats();
let prevFormats = this.quill.getFormat(range.index-1, 1);
formats = DeltaOp.attributes.diff(curFormats, prevFormats) || {};
}
// Check for astral symbols
let length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
this.quill.deleteText(range.index-length, length, Quill.sources.USER);
if (Object.keys(formats).length > 0) {
this.quill.formatLine(range.index-length, length, formats, Quill.sources.USER);
}
this.quill.selection.scrollIntoView();
}
function handleDeleteRange(range) {
const lines = this.quill.getLines(range);
let formats = {};
if (lines.length > 1) {
const firstFormats = lines[0].formats();
const lastFormats = lines[lines.length - 1].formats();
formats = DeltaOp.attributes.diff(lastFormats, firstFormats) || {};
}
this.quill.deleteText(range, Quill.sources.USER);
if (Object.keys(formats).length > 0) {
this.quill.formatLine(range.index, 1, formats, Quill.sources.USER);
}
this.quill.setSelection(range.index, Quill.sources.SILENT);
this.quill.focus();
}
function handleBackspace(range, context) {
if (range.index === 0) return;
let [line, ] = this.quill.scroll.line(range.index);
let formats = {};
if (context.offset === 0) {
let curFormats = line.formats();
let prevFormats = this.quill.getFormat(range.index-1, 1);
formats = DeltaOp.attributes.diff(curFormats, prevFormats) || {};
}
this.quill.deleteText(range.index-1, 1, Quill.sources.USER);
if (Object.keys(formats).length > 0) {
this.quill.formatLine(range.index-1, 1, formats, Quill.sources.USER);
}
this.quill.selection.scrollIntoView();
}