MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / paste

Function paste

src/lib/openFolder.js:712–897  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

710 }
711
712 async function paste() {
713 if (clipBoard.url == null) {
714 alert(strings.warning, "Nothing to paste");
715 return;
716 }
717
718 // Prevent pasting a folder into itself or its subdirectories
719 if (helpers.isDir(clipBoard.$el.dataset.type)) {
720 const sourceUrl = Url.parse(clipBoard.url).url;
721 const targetUrl = Url.parse(url).url;
722
723 // Check if trying to paste folder into itself
724 if (sourceUrl === targetUrl) {
725 alert(strings.warning, "Cannot paste a folder into itself");
726 return;
727 }
728
729 // Check if trying to paste folder into one of its subdirectories
730 if (
731 targetUrl.startsWith(sourceUrl + "/") ||
732 targetUrl.startsWith(sourceUrl + "\\")
733 ) {
734 alert(strings.warning, "Cannot paste a folder into its subdirectory");
735 return;
736 }
737 }
738
739 let CASE = "";
740 const $src = clipBoard.$el;
741 const srcType = $src.dataset.type;
742 const IS_FILE = helpers.isFile(srcType);
743 const IS_DIR = helpers.isDir(srcType);
744 const srcCollapsed = collapsed($src, IS_FILE);
745
746 CASE += IS_FILE ? 1 : 0;
747 CASE += srcCollapsed ? 1 : 0;
748 CASE += $target.collapsed ? 1 : 0;
749
750 startLoading();
751 try {
752 const fs = fsOperation(clipBoard.url);
753 const itemName = Url.basename(clipBoard.url);
754 const possibleConflictUrl = Url.join(url, itemName);
755 const doesExist = await fsOperation(possibleConflictUrl).exists();
756 if (doesExist) {
757 let confirmation = await confirm(
758 strings.warning,
759 strings["already exists"]
760 ? strings["already exists"].replace("{name}", itemName)
761 : `"${itemName}" already exists in this location.`,
762 );
763 if (!confirmation) return;
764 }
765 let newUrl;
766 if (clipBoard.action === "cut") {
767 // Special handling for SAF folders backed by terminal providers - move manually due to SAF limitations
768 if (isTerminalSafUri(clipBoard.url) && IS_DIR) {
769 const moveRecursively = async (sourceUrl, targetParentUrl) => {

Callers 1

execOperationFunction · 0.70

Calls 15

alertFunction · 0.85
collapsedFunction · 0.85
fsOperationFunction · 0.85
confirmFunction · 0.85
isTerminalSafUriFunction · 0.85
moveRecursivelyFunction · 0.85
appendTileFunction · 0.85
createFileTileFunction · 0.85
appendListFunction · 0.85
createFolderTileFunction · 0.85
clearClipboardFunction · 0.85
basenameMethod · 0.80

Tested by

no test coverage detected