MCPcopy Create free account
hub / github.com/TruthHun/BookStack / deleteNearSelection

Function deleteNearSelection

static/editor.md/lib/codemirror/lib/codemirror.js:4604–4625  ·  view source on GitHub ↗
(cm, compute)

Source from the content-addressed store, hash-verified

4602 // Helper for deleting text near the selection(s), used to implement
4603 // backspace, delete, and similar functionality.
4604 function deleteNearSelection(cm, compute) {
4605 var ranges = cm.doc.sel.ranges, kill = [];
4606 // Build up a set of ranges to kill first, merging overlapping
4607 // ranges.
4608 for (var i = 0; i < ranges.length; i++) {
4609 var toKill = compute(ranges[i]);
4610 while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
4611 var replaced = kill.pop();
4612 if (cmp(replaced.from, toKill.from) < 0) {
4613 toKill.from = replaced.from;
4614 break;
4615 }
4616 }
4617 kill.push(toKill);
4618 }
4619 // Next, remove those actual ranges.
4620 runInOp(cm, function() {
4621 for (var i = kill.length - 1; i >= 0; i--)
4622 replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
4623 ensureCursorVisible(cm);
4624 });
4625 }
4626
4627 // Used for horizontal relative motion. Dir is -1 or 1 (left or
4628 // right), unit can be "char", "column" (like char, but doesn't

Callers 1

codemirror.jsFile · 0.70

Calls 5

lstFunction · 0.70
runInOpFunction · 0.70
replaceRangeFunction · 0.70
ensureCursorVisibleFunction · 0.70
cmpFunction · 0.50

Tested by

no test coverage detected