(cm)
| 1343 | // events that indicate IME taking place, but these are not widely |
| 1344 | // supported or compatible enough yet to rely on.) |
| 1345 | function readInput(cm) { |
| 1346 | var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc, sel = doc.sel; |
| 1347 | if (!cm.state.focused || hasSelection(input) || isReadOnly(cm)) return false; |
| 1348 | var text = input.value; |
| 1349 | if (text == prevInput && posEq(sel.from, sel.to)) return false; |
| 1350 | // IE enjoys randomly deselecting our input's text when |
| 1351 | // re-focusing. If the selection is gone but the cursor is at the |
| 1352 | // start of the input, that's probably what happened. |
| 1353 | if (ie && text && input.selectionStart === 0) { |
| 1354 | resetInput(cm, true); |
| 1355 | return false; |
| 1356 | } |
| 1357 | var withOp = !cm.curOp; |
| 1358 | if (withOp) startOperation(cm); |
| 1359 | sel.shift = false; |
| 1360 | var same = 0, l = Math.min(prevInput.length, text.length); |
| 1361 | while (same < l && prevInput[same] == text[same]) ++same; |
| 1362 | var from = sel.from, to = sel.to; |
| 1363 | if (same < prevInput.length) |
| 1364 | from = Pos(from.line, from.ch - (prevInput.length - same)); |
| 1365 | else if (cm.state.overwrite && posEq(from, to) && !cm.state.pasteIncoming) |
| 1366 | to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + (text.length - same))); |
| 1367 | var updateInput = cm.curOp.updateInput; |
| 1368 | makeChange(cm.doc, {from: from, to: to, text: splitLines(text.slice(same)), |
| 1369 | origin: cm.state.pasteIncoming ? "paste" : "+input"}, "end"); |
| 1370 | |
| 1371 | cm.curOp.updateInput = updateInput; |
| 1372 | if (text.length > 1000) input.value = cm.display.prevInput = ""; |
| 1373 | else cm.display.prevInput = text; |
| 1374 | if (withOp) endOperation(cm); |
| 1375 | cm.state.pasteIncoming = false; |
| 1376 | return true; |
| 1377 | } |
| 1378 | |
| 1379 | function resetInput(cm, user) { |
| 1380 | var minimal, selected, doc = cm.doc; |
no test coverage detected