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

Function setSelection

tools/pythonauto/static/codemirrorepl/codemirrorepl.js:1379–1414  ·  view source on GitHub ↗
(from, to, oldFrom, oldTo)

Source from the content-addressed store, hash-verified

1377 // updateLines, since they have to be expressed in the line
1378 // numbers before the update.
1379 function setSelection(from, to, oldFrom, oldTo) {
1380 goalColumn = null;
1381 if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;}
1382 if (posEq(sel.from, from) && posEq(sel.to, to)) return;
1383 if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
1384
1385 // Skip over hidden lines.
1386 if (from.line != oldFrom) {
1387 var from1 = skipHidden(from, oldFrom, sel.from.ch);
1388 // If there is no non-hidden line left, force visibility on current line
1389 if (!from1) setLineHidden(from.line, false);
1390 else from = from1;
1391 }
1392 if (to.line != oldTo) to = skipHidden(to, oldTo, sel.to.ch);
1393
1394 if (posEq(from, to)) sel.inverted = false;
1395 else if (posEq(from, sel.to)) sel.inverted = false;
1396 else if (posEq(to, sel.from)) sel.inverted = true;
1397
1398 if (options.autoClearEmptyLines && posEq(sel.from, sel.to)) {
1399 var head = sel.inverted ? from : to;
1400 if (head.line != sel.from.line && sel.from.line < doc.size) {
1401 var oldLine = getLine(sel.from.line);
1402 if (/^\s+$/.test(oldLine.text))
1403 setTimeout(operation(function() {
1404 if (oldLine.parent && /^\s+$/.test(oldLine.text)) {
1405 var no = lineNo(oldLine);
1406 replaceRange("", {line: no, ch: 0}, {line: no, ch: oldLine.text.length});
1407 }
1408 }, 10));
1409 }
1410 }
1411
1412 sel.from = from; sel.to = to;
1413 selectionChanged = true;
1414 }
1415 function skipHidden(pos, oldLine, oldCh) {
1416 function getNonHidden(dir) {
1417 var lNo = pos.line + dir, end = dir == 1 ? doc.size : -1;

Callers 3

updateLinesNoUndoFunction · 0.70
setSelectionUserFunction · 0.70
setLineHiddenFunction · 0.70

Calls 8

skipHiddenFunction · 0.85
setLineHiddenFunction · 0.85
posEqFunction · 0.70
posLessFunction · 0.70
getLineFunction · 0.70
operationFunction · 0.70
lineNoFunction · 0.70
replaceRangeFunction · 0.70

Tested by

no test coverage detected