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

Function updateSelection

mini-code-editor/cm/lib/codemirror.js:1124–1161  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1122 return resized;
1123 }
1124 function updateSelection() {
1125 var collapsed = posEq(sel.from, sel.to);
1126 var fromPos = localCoords(sel.from, true);
1127 var toPos = collapsed ? fromPos : localCoords(sel.to, true);
1128 var headPos = sel.inverted ? fromPos : toPos, th = textHeight();
1129 var wrapOff = eltOffset(wrapper), lineOff = eltOffset(lineDiv);
1130 inputDiv.style.top = Math.max(0, Math.min(scroller.offsetHeight, headPos.y + lineOff.top - wrapOff.top)) + "px";
1131 inputDiv.style.left = Math.max(0, Math.min(scroller.offsetWidth, headPos.x + lineOff.left - wrapOff.left)) + "px";
1132 if (collapsed) {
1133 cursor.style.top = headPos.y + "px";
1134 cursor.style.left = (options.lineWrapping ? Math.min(headPos.x, lineSpace.offsetWidth) : headPos.x) + "px";
1135 cursor.style.display = "";
1136 selectionDiv.style.display = "none";
1137 } else {
1138 var sameLine = fromPos.y == toPos.y, html = "";
1139 var clientWidth = lineSpace.clientWidth || lineSpace.offsetWidth;
1140 var clientHeight = lineSpace.clientHeight || lineSpace.offsetHeight;
1141 function add(left, top, right, height) {
1142 var rstyle = quirksMode ? "width: " + (!right ? clientWidth : clientWidth - right - left) + "px"
1143 : "right: " + right + "px";
1144 html += '<div class="CodeMirror-selected" style="position: absolute; left: ' + left +
1145 'px; top: ' + top + 'px; ' + rstyle + '; height: ' + height + 'px"></div>';
1146 }
1147 if (sel.from.ch && fromPos.y >= 0) {
1148 var right = sameLine ? clientWidth - toPos.x : 0;
1149 add(fromPos.x, fromPos.y, right, th);
1150 }
1151 var middleStart = Math.max(0, fromPos.y + (sel.from.ch ? th : 0));
1152 var middleHeight = Math.min(toPos.y, clientHeight) - middleStart;
1153 if (middleHeight > 0.2 * th)
1154 add(0, middleStart, 0, middleHeight);
1155 if ((!sameLine || !sel.from.ch) && toPos.y < clientHeight - .5 * th)
1156 add(0, toPos.y, clientWidth - toPos.x, th);
1157 selectionDiv.innerHTML = html;
1158 cursor.style.display = "none";
1159 selectionDiv.style.display = "";
1160 }
1161 }
1162
1163 function setShift(val) {
1164 if (val) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from);

Callers 2

updateDisplayFunction · 0.85
endOperationFunction · 0.85

Calls 5

posEqFunction · 0.85
localCoordsFunction · 0.85
textHeightFunction · 0.85
eltOffsetFunction · 0.85
addFunction · 0.70

Tested by

no test coverage detected