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

Function deleteNearSelection

static/mergely/lib/codemirror.js:4784–4805  ·  view source on GitHub ↗
(cm, compute)

Source from the content-addressed store, hash-verified

4782 // Helper for deleting text near the selection(s), used to implement
4783 // backspace, delete, and similar functionality.
4784 function deleteNearSelection(cm, compute) {
4785 var ranges = cm.doc.sel.ranges, kill = [];
4786 // Build up a set of ranges to kill first, merging overlapping
4787 // ranges.
4788 for (var i = 0; i < ranges.length; i++) {
4789 var toKill = compute(ranges[i]);
4790 while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
4791 var replaced = kill.pop();
4792 if (cmp(replaced.from, toKill.from) < 0) {
4793 toKill.from = replaced.from;
4794 break;
4795 }
4796 }
4797 kill.push(toKill);
4798 }
4799 // Next, remove those actual ranges.
4800 runInOp(cm, function() {
4801 for (var i = kill.length - 1; i >= 0; i--)
4802 replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
4803 ensureCursorVisible(cm);
4804 });
4805 }
4806
4807 // Used for horizontal relative motion. Dir is -1 or 1 (left or
4808 // 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