MCPcopy Create free account
hub / github.com/breck7/scroll / applyTextInput

Function applyTextInput

external/.scrollLibs.js:11140–11198  ·  view source on GitHub ↗
(cm, inserted, deleted, sel, origin)

Source from the content-addressed store, hash-verified

11138 }
11139
11140 function applyTextInput(cm, inserted, deleted, sel, origin) {
11141 var doc = cm.doc
11142 cm.display.shift = false
11143 if (!sel) {
11144 sel = doc.sel
11145 }
11146
11147 var recent = +new Date() - 200
11148 var paste = origin == "paste" || cm.state.pasteIncoming > recent
11149 var textLines = splitLinesAuto(inserted),
11150 multiPaste = null
11151 // When pasting N lines into N selections, insert one line per selection
11152 if (paste && sel.ranges.length > 1) {
11153 if (lastCopied && lastCopied.text.join("\n") == inserted) {
11154 if (sel.ranges.length % lastCopied.text.length == 0) {
11155 multiPaste = []
11156 for (var i = 0; i < lastCopied.text.length; i++) {
11157 multiPaste.push(doc.splitLines(lastCopied.text[i]))
11158 }
11159 }
11160 } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
11161 multiPaste = map(textLines, function (l) {
11162 return [l]
11163 })
11164 }
11165 }
11166
11167 var updateInput = cm.curOp.updateInput
11168 // Normal behavior is to insert the new text into every selection
11169 for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
11170 var range$$1 = sel.ranges[i$1]
11171 var from = range$$1.from(),
11172 to = range$$1.to()
11173 if (range$$1.empty()) {
11174 if (deleted && deleted > 0) {
11175 // Handle deletion
11176 from = Pos(from.line, from.ch - deleted)
11177 } else if (cm.state.overwrite && !paste) {
11178 // Handle overwrite
11179 to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length))
11180 } else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted) {
11181 from = to = Pos(from.line, 0)
11182 }
11183 }
11184 var changeEvent = { from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines, origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input") }
11185 makeChange(cm.doc, changeEvent)
11186 signalLater(cm, "inputRead", cm, changeEvent)
11187 }
11188 if (inserted && !paste) {
11189 triggerElectric(cm, inserted)
11190 }
11191
11192 ensureCursorVisible(cm)
11193 if (cm.curOp.updateInput < 2) {
11194 cm.curOp.updateInput = updateInput
11195 }
11196 cm.curOp.typing = true
11197 cm.state.pasteIncoming = cm.state.cutIncoming = -1

Callers 2

handlePasteFunction · 0.85
.scrollLibs.jsFile · 0.85

Calls 11

mapFunction · 0.85
PosFunction · 0.85
getLineFunction · 0.85
lstFunction · 0.85
makeChangeFunction · 0.85
signalLaterFunction · 0.85
triggerElectricFunction · 0.85
ensureCursorVisibleFunction · 0.85
minMethod · 0.80
joinMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected