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

Function setSelection

mini-code-editor/cm/lib/codemirror.js:1179–1214  ·  view source on GitHub ↗
(from, to, oldFrom, oldTo)

Source from the content-addressed store, hash-verified

1177 // updateLines, since they have to be expressed in the line
1178 // numbers before the update.
1179 function setSelection(from, to, oldFrom, oldTo) {
1180 goalColumn = null;
1181 if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;}
1182 if (posEq(sel.from, from) && posEq(sel.to, to)) return;
1183 if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
1184
1185 // Skip over hidden lines.
1186 if (from.line != oldFrom) {
1187 var from1 = skipHidden(from, oldFrom, sel.from.ch);
1188 // If there is no non-hidden line left, force visibility on current line
1189 if (!from1) setLineHidden(from.line, false);
1190 else from = from1;
1191 }
1192 if (to.line != oldTo) to = skipHidden(to, oldTo, sel.to.ch);
1193
1194 if (posEq(from, to)) sel.inverted = false;
1195 else if (posEq(from, sel.to)) sel.inverted = false;
1196 else if (posEq(to, sel.from)) sel.inverted = true;
1197
1198 if (options.autoClearEmptyLines && posEq(sel.from, sel.to)) {
1199 var head = sel.inverted ? from : to;
1200 if (head.line != sel.from.line && sel.from.line < doc.size) {
1201 var oldLine = getLine(sel.from.line);
1202 if (/^\s+$/.test(oldLine.text))
1203 setTimeout(operation(function() {
1204 if (oldLine.parent && /^\s+$/.test(oldLine.text)) {
1205 var no = lineNo(oldLine);
1206 replaceRange("", {line: no, ch: 0}, {line: no, ch: oldLine.text.length});
1207 }
1208 }, 10));
1209 }
1210 }
1211
1212 sel.from = from; sel.to = to;
1213 selectionChanged = true;
1214 }
1215 function skipHidden(pos, oldLine, oldCh) {
1216 function getNonHidden(dir) {
1217 var lNo = pos.line + dir, end = dir == 1 ? doc.size : -1;

Callers 3

updateLinesNoUndoFunction · 0.85
setSelectionUserFunction · 0.85
setLineHiddenFunction · 0.85

Calls 8

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

Tested by

no test coverage detected