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

Function clipPostChange

tools/pythonauto/static/codemirror/codemirror.js:2289–2302  ·  view source on GitHub ↗
(doc, change, pos)

Source from the content-addressed store, hash-verified

2287
2288 // Make sure a position will be valid after the given change.
2289 function clipPostChange(doc, change, pos) {
2290 if (!posLess(change.from, pos)) return clipPos(doc, pos);
2291 var diff = (change.text.length - 1) - (change.to.line - change.from.line);
2292 if (pos.line > change.to.line + diff) {
2293 var preLine = pos.line - diff, lastLine = doc.first + doc.size - 1;
2294 if (preLine > lastLine) return Pos(lastLine, getLine(doc, lastLine).text.length);
2295 return clipToLen(pos, getLine(doc, preLine).text.length);
2296 }
2297 if (pos.line == change.to.line + diff)
2298 return clipToLen(pos, lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0) +
2299 getLine(doc, change.to.line).text.length - change.to.ch);
2300 var inside = pos.line - change.from.line;
2301 return clipToLen(pos, change.text[inside].length + (inside ? 0 : change.from.ch));
2302 }
2303
2304 // Hint can be null|"end"|"start"|"around"|{anchor,head}
2305 function computeSelAfterChange(doc, change, hint) {

Callers 1

computeSelAfterChangeFunction · 0.85

Calls 6

PosFunction · 0.85
posLessFunction · 0.70
clipPosFunction · 0.70
getLineFunction · 0.70
clipToLenFunction · 0.70
lstFunction · 0.70

Tested by

no test coverage detected