Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleKeyDown: function (view, event) {
if (event.code === 'Backspace') {
const sel = view.state.selection;
const pos = sel.$from;
let tr = view.state.tr;
// what if they delete a region??
const beforeSel = Selection.findFrom(view.state.doc.resolve(sel.from - 1), -1, true);
const marks = beforeSel.$from.marks();
const hasDiff = marks.find((mark) => {
return (mark.type.name === 'diff_plus');
});
const deleteStep = replaceStep(tr.doc, beforeSel.from, sel.from, Slice.empty);
if (hasDiff) {
// need to actually delete it but then avoid random deletions
this.storeStep(deleteStep);
tr.step(deleteStep);
tr.setMeta('backdelete', true);
view.dispatch(tr);
return true;
}
// is this step size always 1??
const newOffset = { index: beforeSel.from, size: 1 };
this.storeStep(deleteStep);
this.stepOffsets.push(newOffset);
this.storeOffset(newOffset);
tr = tr.addMark(beforeSel.from, sel.from, schema.mark('diff_minus', { commitID: this.tracker.uuid }));
tr = tr.setSelection(beforeSel);
}
}
if (isSpaceOperation) {
tr = tr.addMark(newStart, newEnd, schema.mark('diff_plus', { commitID: this.tracker.uuid }));
return;
}
tr = tr.step(inverse);
const slice = step.slice.content;
const possibleInsert = tr.mapping.map(newEnd, 1);
if (step.slice.size > 0) {
const insertstep = replaceStep(oldState.doc, possibleInsert, possibleInsert, (step.slice.size > 0) ? step.slice : Slice.empty);
const newOffset = { index: oldEnd, size: inverse.slice.size };
this.stepOffsets.push(newOffset);
this.storeOffset(newOffset);
try {
tr = tr.step(insertstep);
} catch (err) {
console.log('cannot do this!', insertstep, step);
console.log(err);
}
tr = tr.addMark(oldStart, oldEnd, schema.mark('diff_minus', { commitID: this.tracker.uuid }));
const insertStart = tr.mapping.map(newEnd, -1);
const insertEnd = tr.mapping.map(newEnd, 1);
tr = tr.addMark(insertStart, insertEnd, schema.mark('diff_plus', { commitID: this.tracker.uuid }));
} else {
const insertStart = tr.mapping.map(newEnd, -1);
const insertEnd = tr.mapping.map(newEnd, 1);