MCPcopy
hub / github.com/hokein/electron-sample-apps / replaceRange

Function replaceRange

mini-code-editor/cm/lib/codemirror.js:780–799  ·  view source on GitHub ↗
(code, from, to)

Source from the content-addressed store, hash-verified

778 }
779
780 function replaceRange(code, from, to) {
781 from = clipPos(from);
782 if (!to) to = from; else to = clipPos(to);
783 code = splitLines(code);
784 function adjustPos(pos) {
785 if (posLess(pos, from)) return pos;
786 if (!posLess(to, pos)) return end;
787 var line = pos.line + code.length - (to.line - from.line) - 1;
788 var ch = pos.ch;
789 if (pos.line == to.line)
790 ch += code[code.length-1].length - (to.ch - (to.line == from.line ? from.ch : 0));
791 return {line: line, ch: ch};
792 }
793 var end;
794 replaceRange1(code, from, to, function(end1) {
795 end = end1;
796 return {from: adjustPos(sel.from), to: adjustPos(sel.to)};
797 });
798 return end;
799 }
800 function replaceSelection(code, collapse) {
801 replaceRange1(splitLines(code), sel.from, sel.to, function(end) {
802 if (collapse == "end") return {from: end, to: end};

Callers 6

CodeMirrorFunction · 0.85
loadFileFunction · 0.85
onDropFunction · 0.85
setSelectionFunction · 0.85
deleteHFunction · 0.85
indentLineFunction · 0.85

Calls 3

clipPosFunction · 0.85
replaceRange1Function · 0.85
adjustPosFunction · 0.85

Tested by

no test coverage detected