From d3079be007142d5332e76d44f4456d7cc651447c Mon Sep 17 00:00:00 2001 From: mirivlad Date: Sat, 20 Jun 2026 20:23:02 +0800 Subject: [PATCH] fix: Cut/copy/paste path consistency and folder cut support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pasteEntry: source path now scoped for readText, relative for trash - cutEntry: removed folder guard — folder cut via api.files.move - copyEntry: hidden from context menu for folders (not supported) - Clipboard object now carries isFolder flag --- plugins/files/frontend/src/index.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/files/frontend/src/index.js b/plugins/files/frontend/src/index.js index 175c40c..8cf49f1 100644 --- a/plugins/files/frontend/src/index.js +++ b/plugins/files/frontend/src/index.js @@ -713,7 +713,9 @@ ctxMenu.appendChild(ctxItem('Duplicate', '', function () { duplicateEntry(entry); })); ctxMenu.appendChild(ctxSep()); ctxMenu.appendChild(ctxItem('Cut', '', function () { cutEntry(entry); })); - ctxMenu.appendChild(ctxItem('Copy', '', function () { copyEntry(entry); })); + if (entry.type !== 'folder') { + ctxMenu.appendChild(ctxItem('Copy', '', function () { copyEntry(entry); })); + } ctxMenu.appendChild(ctxSep()); ctxMenu.appendChild(ctxItem('Move to Trash', 'danger', function () { trashEntry(entry); })); } else { @@ -773,9 +775,8 @@ function cutEntry(entry) { if (!entry) return; - if (entry.type === 'folder') { console.log('[files] Cut for folders not yet supported'); return; } console.log('[files] Cut:', entry.relativePath); - window.__filesClipboard = { action: 'cut', path: entry.relativePath, name: entry.name }; + window.__filesClipboard = { action: 'cut', path: entry.relativePath, name: entry.name, isFolder: entry.type === 'folder' }; updateButtons(); } @@ -783,14 +784,16 @@ if (!entry) return; if (entry.type === 'folder') { console.log('[files] Copy for folders not yet supported'); return; } console.log('[files] Copy:', entry.relativePath); - window.__filesClipboard = { action: 'copy', path: entry.relativePath, name: entry.name }; + window.__filesClipboard = { action: 'copy', path: entry.relativePath, name: entry.name, isFolder: false }; updateButtons(); } function pasteEntry() { var clip = window.__filesClipboard; if (!clip || !clip.path) return; - var from = clip.path; + var fromRelative = clip.path; + var fromScoped = scopedPath(fromRelative); + var isFolder = clip.isFolder; var clipName = clip.name; var dot = clipName.lastIndexOf('.'); var base = dot > 0 ? clipName.slice(0, dot) : clipName; @@ -807,11 +810,16 @@ } return tryName(n + 1); }, function () { - return api.files.readText(from).then(function (content) { + if (isFolder && clip.action === 'cut') { + return api.files.move(fromRelative, to, { overwrite: false }).then(function () { + return true; + }); + } + return api.files.readText(fromScoped).then(function (content) { return api.files.writeText(to, content, { createIfMissing: true, overwrite: false }); }).then(function () { if (clip.action === 'cut') { - return api.files.trash(from); + return api.files.trash(fromRelative); } }); });