MCPcopy Index your code
hub / github.com/DHTMLX/gantt / applyTextInput

Function applyTextInput

samples/common/codehighlight/codemirror.js:8104–8150  ·  view source on GitHub ↗
(cm, inserted, deleted, sel, origin)

Source from the content-addressed store, hash-verified

8102 }
8103
8104 function applyTextInput(cm, inserted, deleted, sel, origin) {
8105 var doc = cm.doc;
8106 cm.display.shift = false;
8107 if (!sel) { sel = doc.sel; }
8108
8109 var recent = +new Date - 200;
8110 var paste = origin == "paste" || cm.state.pasteIncoming > recent;
8111 var textLines = splitLinesAuto(inserted), multiPaste = null;
8112 // When pasting N lines into N selections, insert one line per selection
8113 if (paste && sel.ranges.length > 1) {
8114 if (lastCopied && lastCopied.text.join("\n") == inserted) {
8115 if (sel.ranges.length % lastCopied.text.length == 0) {
8116 multiPaste = [];
8117 for (var i = 0; i < lastCopied.text.length; i++)
8118 { multiPaste.push(doc.splitLines(lastCopied.text[i])); }
8119 }
8120 } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
8121 multiPaste = map(textLines, function (l) { return [l]; });
8122 }
8123 }
8124
8125 var updateInput = cm.curOp.updateInput;
8126 // Normal behavior is to insert the new text into every selection
8127 for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
8128 var range = sel.ranges[i$1];
8129 var from = range.from(), to = range.to();
8130 if (range.empty()) {
8131 if (deleted && deleted > 0) // Handle deletion
8132 { from = Pos(from.line, from.ch - deleted); }
8133 else if (cm.state.overwrite && !paste) // Handle overwrite
8134 { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); }
8135 else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == textLines.join("\n"))
8136 { from = to = Pos(from.line, 0); }
8137 }
8138 var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
8139 origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input")};
8140 makeChange(cm.doc, changeEvent);
8141 signalLater(cm, "inputRead", cm, changeEvent);
8142 }
8143 if (inserted && !paste)
8144 { triggerElectric(cm, inserted); }
8145
8146 ensureCursorVisible(cm);
8147 if (cm.curOp.updateInput < 2) { cm.curOp.updateInput = updateInput; }
8148 cm.curOp.typing = true;
8149 cm.state.pasteIncoming = cm.state.cutIncoming = -1;
8150 }
8151
8152 function handlePaste(e, cm) {
8153 var pasted = e.clipboardData && e.clipboardData.getData("Text");

Callers 2

handlePasteFunction · 0.85
codemirror.jsFile · 0.85

Calls 8

mapFunction · 0.85
PosFunction · 0.85
getLineFunction · 0.85
lstFunction · 0.85
makeChangeFunction · 0.85
signalLaterFunction · 0.85
triggerElectricFunction · 0.85
ensureCursorVisibleFunction · 0.85

Tested by

no test coverage detected