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

Function onCopyCut

external/.scrollLibs.js:12060–12105  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

12058 })
12059
12060 function onCopyCut(e) {
12061 if (signalDOMEvent(cm, e)) {
12062 return
12063 }
12064 if (cm.somethingSelected()) {
12065 setLastCopied({ lineWise: false, text: cm.getSelections() })
12066 if (e.type == "cut") {
12067 cm.replaceSelection("", null, "cut")
12068 }
12069 } else if (!cm.options.lineWiseCopyCut) {
12070 return
12071 } else {
12072 var ranges = copyableRanges(cm)
12073 setLastCopied({ lineWise: true, text: ranges.text })
12074 if (e.type == "cut") {
12075 cm.operation(function () {
12076 cm.setSelections(ranges.ranges, 0, sel_dontScroll)
12077 cm.replaceSelection("", null, "cut")
12078 })
12079 }
12080 }
12081 if (e.clipboardData) {
12082 e.clipboardData.clearData()
12083 var content = lastCopied.text.join("\n")
12084 // iOS exposes the clipboard API, but seems to discard content inserted into it
12085 e.clipboardData.setData("Text", content)
12086 if (e.clipboardData.getData("Text") == content) {
12087 e.preventDefault()
12088 return
12089 }
12090 }
12091 // Old-fashioned briefly-focus-a-textarea hack
12092 var kludge = hiddenTextarea(),
12093 te = kludge.firstChild
12094 cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild)
12095 te.value = lastCopied.text.join("\n")
12096 var hadFocus = document.activeElement
12097 selectInput(te)
12098 setTimeout(function () {
12099 cm.display.lineSpace.removeChild(kludge)
12100 hadFocus.focus()
12101 if (hadFocus == div) {
12102 input.showPrimarySelection()
12103 }
12104 }, 50)
12105 }
12106 on(div, "copy", onCopyCut)
12107 on(div, "cut", onCopyCut)
12108 }

Callers

nothing calls this directly

Calls 7

signalDOMEventFunction · 0.85
setLastCopiedFunction · 0.85
copyableRangesFunction · 0.85
hiddenTextareaFunction · 0.85
selectInputFunction · 0.85
getDataMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected