Skip to content

Commit 021c065

Browse files
committed
breaking: preserve clipboard after copy
1 parent c8d651e commit 021c065

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/svelte-file-tree/src/lib/components/Tree.svelte

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
}
9595
}
9696
},
97+
shouldClearClipboard = (operation) => operation === "cut",
9798
onResolveNameConflict = () => "cancel",
9899
onCircularReference = noop,
99100
canCopy = truePredicate,
@@ -429,7 +430,11 @@
429430
}
430431
431432
export async function paste(destination?: TreeItemState<TFile, TFolder>) {
432-
let didPaste = false;
433+
if (pasteOperation === undefined) {
434+
return false;
435+
}
436+
437+
let didPaste;
433438
switch (pasteOperation) {
434439
case "copy": {
435440
didPaste = await copy(destination);
@@ -445,8 +450,11 @@
445450
return false;
446451
}
447452
448-
clipboardIds.clear();
449-
pasteOperation = undefined;
453+
if (shouldClearClipboard(pasteOperation)) {
454+
clipboardIds.clear();
455+
pasteOperation = undefined;
456+
}
457+
450458
return true;
451459
}
452460

packages/svelte-file-tree/src/lib/components/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface TreeProps<
8282
isItemDisabled?: (node: TFile | TFolder) => boolean;
8383
isItemHidden?: (node: TFile | TFolder) => boolean;
8484
copyNode?: (node: TFile | TFolder) => TFile | TFolder;
85+
shouldClearClipboard?: (operation: PasteOperation) => boolean;
8586
onResolveNameConflict?: (
8687
args: OnResolveNameConflictArgs<TFile, TFolder>,
8788
) => MaybePromise<NameConflictResolution>;

0 commit comments

Comments
 (0)