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

Function onCopyCut

static/editor.md/lib/codemirror/lib/codemirror.js:1551–1582  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

1549 });
1550
1551 function onCopyCut(e) {
1552 if (cm.somethingSelected()) {
1553 lastCopied = cm.getSelections();
1554 if (e.type == "cut") cm.replaceSelection("", null, "cut");
1555 } else {
1556 var ranges = copyableRanges(cm);
1557 lastCopied = ranges.text;
1558 if (e.type == "cut") {
1559 cm.operation(function() {
1560 cm.setSelections(ranges.ranges, 0, sel_dontScroll);
1561 cm.replaceSelection("", null, "cut");
1562 });
1563 }
1564 }
1565 // iOS exposes the clipboard API, but seems to discard content inserted into it
1566 if (e.clipboardData && !ios) {
1567 e.preventDefault();
1568 e.clipboardData.clearData();
1569 e.clipboardData.setData("text/plain", lastCopied.join("\n"));
1570 } else {
1571 // Old-fashioned briefly-focus-a-textarea hack
1572 var kludge = hiddenTextarea(), te = kludge.firstChild;
1573 cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
1574 te.value = lastCopied.join("\n");
1575 var hadFocus = document.activeElement;
1576 selectInput(te);
1577 setTimeout(function() {
1578 cm.display.lineSpace.removeChild(kludge);
1579 hadFocus.focus();
1580 }, 50);
1581 }
1582 }
1583 on(div, "copy", onCopyCut);
1584 on(div, "cut", onCopyCut);
1585 },

Callers

nothing calls this directly

Calls 3

copyableRangesFunction · 0.70
hiddenTextareaFunction · 0.70
selectInputFunction · 0.70

Tested by

no test coverage detected