MCPcopy Index your code
hub / github.com/TruthHun/BookStack / applyTextInput

Function applyTextInput

static/mergely/lib/codemirror.js:1102–1145  ·  view source on GitHub ↗
(cm, inserted, deleted, sel, origin)

Source from the content-addressed store, hash-verified

1100 var lastCopied = null;
1101
1102 function applyTextInput(cm, inserted, deleted, sel, origin) {
1103 var doc = cm.doc;
1104 cm.display.shift = false;
1105 if (!sel) sel = doc.sel;
1106
1107 var paste = cm.state.pasteIncoming || origin == "paste";
1108 var textLines = doc.splitLines(inserted), multiPaste = null;
1109 // When pasing N lines into N selections, insert one line per selection
1110 if (paste && sel.ranges.length > 1) {
1111 if (lastCopied && lastCopied.join("\n") == inserted) {
1112 if (sel.ranges.length % lastCopied.length == 0) {
1113 multiPaste = [];
1114 for (var i = 0; i < lastCopied.length; i++)
1115 multiPaste.push(doc.splitLines(lastCopied[i]));
1116 }
1117 } else if (textLines.length == sel.ranges.length) {
1118 multiPaste = map(textLines, function(l) { return [l]; });
1119 }
1120 }
1121
1122 // Normal behavior is to insert the new text into every selection
1123 for (var i = sel.ranges.length - 1; i >= 0; i--) {
1124 var range = sel.ranges[i];
1125 var from = range.from(), to = range.to();
1126 if (range.empty()) {
1127 if (deleted && deleted > 0) // Handle deletion
1128 from = Pos(from.line, from.ch - deleted);
1129 else if (cm.state.overwrite && !paste) // Handle overwrite
1130 to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
1131 }
1132 var updateInput = cm.curOp.updateInput;
1133 var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
1134 origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")};
1135 makeChange(cm.doc, changeEvent);
1136 signalLater(cm, "inputRead", cm, changeEvent);
1137 }
1138 if (inserted && !paste)
1139 triggerElectric(cm, inserted);
1140
1141 ensureCursorVisible(cm);
1142 cm.curOp.updateInput = updateInput;
1143 cm.curOp.typing = true;
1144 cm.state.pasteIncoming = cm.state.cutIncoming = false;
1145 }
1146
1147 function handlePaste(e, cm) {
1148 var pasted = e.clipboardData && e.clipboardData.getData("text/plain");

Callers 2

handlePasteFunction · 0.70
codemirror.jsFile · 0.70

Calls 7

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

Tested by

no test coverage detected