MCPcopy Create free account
hub / github.com/sql-js/sql.js / readInput

Function readInput

GUI/codemirror/lib/codemirror.js:2223–2300  ·  view source on GitHub ↗
(cm)

Source from the content-addressed store, hash-verified

2221 // seen text (can be empty), which is stored in prevInput (we must
2222 // not reset the textarea when typing, because that breaks IME).
2223 function readInput(cm) {
2224 var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc;
2225 // Since this is called a *lot*, try to bail out as cheaply as
2226 // possible when it is clear that nothing happened. hasSelection
2227 // will be the case when there is a lot of text in the textarea,
2228 // in which case reading its value would be expensive.
2229 if (!cm.state.focused || (hasSelection(input) && !prevInput) || isReadOnly(cm) || cm.options.disableInput)
2230 return false;
2231 // See paste handler for more on the fakedLastChar kludge
2232 if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
2233 input.value = input.value.substring(0, input.value.length - 1);
2234 cm.state.fakedLastChar = false;
2235 }
2236 var text = input.value;
2237 // If nothing changed, bail.
2238 if (text == prevInput && !cm.somethingSelected()) return false;
2239 // Work around nonsensical selection resetting in IE9/10
2240 if (ie && !ie_upto8 && cm.display.inputHasSelection === text) {
2241 resetInput(cm);
2242 return false;
2243 }
2244
2245 var withOp = !cm.curOp;
2246 if (withOp) startOperation(cm);
2247 cm.display.shift = false;
2248
2249 // Find the part of the input that is actually new
2250 var same = 0, l = Math.min(prevInput.length, text.length);
2251 while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
2252 var inserted = text.slice(same), textLines = splitLines(inserted);
2253
2254 // When pasing N lines into N selections, insert one line per selection
2255 var multiPaste = cm.state.pasteIncoming && textLines.length > 1 && doc.sel.ranges.length == textLines.length;
2256
2257 // Normal behavior is to insert the new text into every selection
2258 for (var i = doc.sel.ranges.length - 1; i >= 0; i--) {
2259 var range = doc.sel.ranges[i];
2260 var from = range.from(), to = range.to();
2261 // Handle deletion
2262 if (same < prevInput.length)
2263 from = Pos(from.line, from.ch - (prevInput.length - same));
2264 // Handle overwrite
2265 else if (cm.state.overwrite && range.empty() && !cm.state.pasteIncoming)
2266 to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
2267 var updateInput = cm.curOp.updateInput;
2268 var changeEvent = {from: from, to: to, text: multiPaste ? [textLines[i]] : textLines,
2269 origin: cm.state.pasteIncoming ? "paste" : cm.state.cutIncoming ? "cut" : "+input"};
2270 makeChange(cm.doc, changeEvent);
2271 signalLater(cm, "inputRead", cm, changeEvent);
2272 // When an 'electric' character is inserted, immediately trigger a reindent
2273 if (inserted && !cm.state.pasteIncoming && cm.options.electricChars &&
2274 cm.options.smartIndent && range.head.ch < 100 &&
2275 (!i || doc.sel.ranges[i - 1].head.line != range.head.line)) {
2276 var mode = cm.getModeAt(range.head);
2277 if (mode.electricChars) {
2278 for (var j = 0; j < mode.electricChars.length; j++)
2279 if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
2280 indentLine(cm, range.head.line, "smart");

Callers 3

slowPollFunction · 0.85
pFunction · 0.85
doHandleBindingFunction · 0.85

Calls 10

isReadOnlyFunction · 0.85
resetInputFunction · 0.85
startOperationFunction · 0.85
getLineFunction · 0.85
lstFunction · 0.85
makeChangeFunction · 0.85
signalLaterFunction · 0.85
indentLineFunction · 0.85
ensureCursorVisibleFunction · 0.85
endOperationFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…