MCPcopy Create free account
hub / github.com/TruthHun/BookStack / onCopyCut

Function onCopyCut

static/mergely/lib/codemirror.js:1618–1652  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

1616 });
1617
1618 function onCopyCut(e) {
1619 if (signalDOMEvent(cm, e)) return
1620 if (cm.somethingSelected()) {
1621 lastCopied = cm.getSelections();
1622 if (e.type == "cut") cm.replaceSelection("", null, "cut");
1623 } else if (!cm.options.lineWiseCopyCut) {
1624 return;
1625 } else {
1626 var ranges = copyableRanges(cm);
1627 lastCopied = ranges.text;
1628 if (e.type == "cut") {
1629 cm.operation(function() {
1630 cm.setSelections(ranges.ranges, 0, sel_dontScroll);
1631 cm.replaceSelection("", null, "cut");
1632 });
1633 }
1634 }
1635 // iOS exposes the clipboard API, but seems to discard content inserted into it
1636 if (e.clipboardData && !ios) {
1637 e.preventDefault();
1638 e.clipboardData.clearData();
1639 e.clipboardData.setData("text/plain", lastCopied.join("\n"));
1640 } else {
1641 // Old-fashioned briefly-focus-a-textarea hack
1642 var kludge = hiddenTextarea(), te = kludge.firstChild;
1643 cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
1644 te.value = lastCopied.join("\n");
1645 var hadFocus = document.activeElement;
1646 selectInput(te);
1647 setTimeout(function() {
1648 cm.display.lineSpace.removeChild(kludge);
1649 hadFocus.focus();
1650 }, 50);
1651 }
1652 }
1653 on(div, "copy", onCopyCut);
1654 on(div, "cut", onCopyCut);
1655 },

Callers

nothing calls this directly

Calls 4

signalDOMEventFunction · 0.70
copyableRangesFunction · 0.70
hiddenTextareaFunction · 0.70
selectInputFunction · 0.70

Tested by

no test coverage detected