(cm)
| 1493 | // events that indicate IME taking place, but these are not widely |
| 1494 | // supported or compatible enough yet to rely on.) |
| 1495 | function readInput(cm) { |
| 1496 | var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc, sel = doc.sel; |
| 1497 | if (!cm.state.focused || hasSelection(input) || isReadOnly(cm) || cm.options.disableInput) return false; |
| 1498 | if (cm.state.pasteIncoming && cm.state.fakedLastChar) { |
| 1499 | input.value = input.value.substring(0, input.value.length - 1); |
| 1500 | cm.state.fakedLastChar = false; |
| 1501 | } |
| 1502 | var text = input.value; |
| 1503 | if (text == prevInput && posEq(sel.from, sel.to)) return false; |
| 1504 | if (ie && !ie_lt9 && cm.display.inputHasSelection === text) { |
| 1505 | resetInput(cm, true); |
| 1506 | return false; |
| 1507 | } |
| 1508 | |
| 1509 | var withOp = !cm.curOp; |
| 1510 | if (withOp) startOperation(cm); |
| 1511 | sel.shift = false; |
| 1512 | var same = 0, l = Math.min(prevInput.length, text.length); |
| 1513 | while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same; |
| 1514 | var from = sel.from, to = sel.to; |
| 1515 | var inserted = text.slice(same); |
| 1516 | if (same < prevInput.length) |
| 1517 | from = Pos(from.line, from.ch - (prevInput.length - same)); |
| 1518 | else if (cm.state.overwrite && posEq(from, to) && !cm.state.pasteIncoming) |
| 1519 | to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + inserted.length)); |
| 1520 | |
| 1521 | var updateInput = cm.curOp.updateInput; |
| 1522 | var changeEvent = {from: from, to: to, text: splitLines(inserted), |
| 1523 | origin: cm.state.pasteIncoming ? "paste" : cm.state.cutIncoming ? "cut" : "+input"}; |
| 1524 | makeChange(cm.doc, changeEvent, "end"); |
| 1525 | cm.curOp.updateInput = updateInput; |
| 1526 | signalLater(cm, "inputRead", cm, changeEvent); |
| 1527 | if (inserted && !cm.state.pasteIncoming && cm.options.electricChars && |
| 1528 | cm.options.smartIndent && sel.head.ch < 100) { |
| 1529 | var electric = cm.getModeAt(sel.head).electricChars; |
| 1530 | if (electric) for (var i = 0; i < electric.length; i++) |
| 1531 | if (inserted.indexOf(electric.charAt(i)) > -1) { |
| 1532 | indentLine(cm, sel.head.line, "smart"); |
| 1533 | break; |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | if (text.length > 1000 || text.indexOf("\n") > -1) input.value = cm.display.prevInput = ""; |
| 1538 | else cm.display.prevInput = text; |
| 1539 | if (withOp) endOperation(cm); |
| 1540 | cm.state.pasteIncoming = cm.state.cutIncoming = false; |
| 1541 | return true; |
| 1542 | } |
| 1543 | |
| 1544 | function resetInput(cm, user) { |
| 1545 | var minimal, selected, doc = cm.doc; |
no test coverage detected