MCPcopy Index your code
hub / github.com/csev/py4e / replaceRange

Function replaceRange

tools/pythonauto/static/codemirrorepl/codemirrorepl.js:980–999  ·  view source on GitHub ↗
(code, from, to)

Source from the content-addressed store, hash-verified

978 }
979
980 function replaceRange(code, from, to) {
981 from = clipPos(from);
982 if (!to) to = from; else to = clipPos(to);
983 code = splitLines(code);
984 function adjustPos(pos) {
985 if (posLess(pos, from)) return pos;
986 if (!posLess(to, pos)) return end;
987 var line = pos.line + code.length - (to.line - from.line) - 1;
988 var ch = pos.ch;
989 if (pos.line == to.line)
990 ch += code[code.length-1].length - (to.ch - (to.line == from.line ? from.ch : 0));
991 return {line: line, ch: ch};
992 }
993 var end;
994 replaceRange1(code, from, to, function(end1) {
995 end = end1;
996 return {from: adjustPos(sel.from), to: adjustPos(sel.to)};
997 });
998 return end;
999 }
1000 function replaceSelection(code, collapse) {
1001 replaceRange1(splitLines(code), sel.from, sel.to, function(end) {
1002 if (collapse == "end") return {from: end, to: end};

Callers 6

CodeMirrorFunction · 0.70
loadFileFunction · 0.70
onDropFunction · 0.70
setSelectionFunction · 0.70
deleteHFunction · 0.70
indentLineFunction · 0.70

Calls 3

replaceRange1Function · 0.85
clipPosFunction · 0.70
adjustPosFunction · 0.70

Tested by

no test coverage detected