fix copied & cut stores

This commit is contained in:
vcoppe
2025-10-18 09:36:55 +02:00
parent 4ae0bc25c2
commit 9fa8fe5767
5 changed files with 18 additions and 17 deletions

View File

@@ -71,7 +71,7 @@
} from '$lib/logic/file-actions'; } from '$lib/logic/file-actions';
import { fileStateCollection } from '$lib/logic/file-state'; import { fileStateCollection } from '$lib/logic/file-state';
import { fileActionManager } from '$lib/logic/file-action-manager'; import { fileActionManager } from '$lib/logic/file-action-manager';
import { selection } from '$lib/logic/selection'; import { copied, selection } from '$lib/logic/selection';
const { const {
distanceUnits, distanceUnits,
@@ -317,10 +317,10 @@
<Shortcut key="X" ctrl={true} /> <Shortcut key="X" ctrl={true} />
</Menubar.Item> </Menubar.Item>
<Menubar.Item <Menubar.Item
disabled={selection.copied === undefined || disabled={$copied === undefined ||
selection.copied.length === 0 || $copied.length === 0 ||
($selection.size > 0 && ($selection.size > 0 &&
!allowedPastes[selection.copied[0].level].includes( !allowedPastes[$copied[0].level].includes(
$selection.getSelected().pop()?.level $selection.getSelected().pop()?.level
))} ))}
onclick={pasteSelection} onclick={pasteSelection}

View File

@@ -10,7 +10,7 @@
import { settings } from '$lib/logic/settings'; import { settings } from '$lib/logic/settings';
import { fileStateCollection } from '$lib/logic/file-state'; import { fileStateCollection } from '$lib/logic/file-state';
import { createFile, pasteSelection } from '$lib/logic/file-actions'; import { createFile, pasteSelection } from '$lib/logic/file-actions';
import { selection } from '$lib/logic/selection'; import { selection, copied } from '$lib/logic/selection';
let { let {
orientation, orientation,
@@ -86,9 +86,9 @@
</ContextMenu.Item> </ContextMenu.Item>
<ContextMenu.Separator /> <ContextMenu.Separator />
<ContextMenu.Item <ContextMenu.Item
disabled={selection.copied === undefined || disabled={$copied === undefined ||
selection.copied.length === 0 || $copied.length === 0 ||
!allowedPastes[selection.copied[0].level].includes(ListLevel.ROOT)} !allowedPastes[$copied[0].level].includes(ListLevel.ROOT)}
onclick={pasteSelection} onclick={pasteSelection}
> >
<ClipboardPaste size="16" class="mr-1" /> <ClipboardPaste size="16" class="mr-1" />

View File

@@ -37,7 +37,7 @@
import { editStyle } from '$lib/components/file-list/style/utils.svelte'; import { editStyle } from '$lib/components/file-list/style/utils.svelte';
import { waypointPopup } from '$lib/components/map/gpx-layer/GPXLayerPopup'; import { waypointPopup } from '$lib/components/map/gpx-layer/GPXLayerPopup';
import { getSymbolKey, symbols } from '$lib/assets/symbols'; import { getSymbolKey, symbols } from '$lib/assets/symbols';
import { selection } from '$lib/logic/selection'; import { selection, copied, cut } from '$lib/logic/selection';
import { map } from '$lib/components/map/map'; import { map } from '$lib/components/map/map';
import { fileActions, pasteSelection } from '$lib/logic/file-actions'; import { fileActions, pasteSelection } from '$lib/logic/file-actions';
@@ -151,8 +151,7 @@
<span <span
class="w-full text-left truncate py-1 flex flex-row items-center {hidden class="w-full text-left truncate py-1 flex flex-row items-center {hidden
? 'text-muted-foreground' ? 'text-muted-foreground'
: ''} {selection.cut && : ''} {$cut && $copied?.some((i) => i.getFullId() === item.getFullId())
selection.copied?.some((i) => i.getFullId() === item.getFullId())
? 'text-muted-foreground' ? 'text-muted-foreground'
: ''}" : ''}"
oncontextmenu={(e) => { oncontextmenu={(e) => {
@@ -310,9 +309,9 @@
<Shortcut key="X" ctrl={true} /> <Shortcut key="X" ctrl={true} />
</ContextMenu.Item> </ContextMenu.Item>
<ContextMenu.Item <ContextMenu.Item
disabled={selection.copied === undefined || disabled={$copied === undefined ||
selection.copied.length === 0 || $copied.length === 0 ||
!allowedPastes[selection.copied[0].level].includes(item.level)} !allowedPastes[$copied[0].level].includes(item.level)}
onclick={pasteSelection} onclick={pasteSelection}
> >
<ClipboardPaste size="16" class="mr-1" /> <ClipboardPaste size="16" class="mr-1" />

View File

@@ -1,6 +1,6 @@
import { fileStateCollection } from '$lib/logic/file-state'; import { fileStateCollection } from '$lib/logic/file-state';
import { fileActionManager } from '$lib/logic/file-action-manager'; import { fileActionManager } from '$lib/logic/file-action-manager';
import { selection } from '$lib/logic/selection'; import { copied, cut, selection } from '$lib/logic/selection';
import { currentTool, Tool } from '$lib/components/toolbar/tools'; import { currentTool, Tool } from '$lib/components/toolbar/tools';
import type { SplitType } from '$lib/components/toolbar/tools/scissors/scissors'; import type { SplitType } from '$lib/components/toolbar/tools/scissors/scissors';
import { import {
@@ -927,7 +927,7 @@ export const fileActions = {
}; };
export function pasteSelection() { export function pasteSelection() {
let fromItems = selection.copied; let fromItems = get(copied);
if (fromItems === undefined || fromItems.length === 0) { if (fromItems === undefined || fromItems.length === 0) {
return; return;
} }
@@ -1007,7 +1007,7 @@ export function pasteSelection() {
} }
if (fromItems.length === toItems.length) { if (fromItems.length === toItems.length) {
moveItems(fromParent, toParent, fromItems, toItems, selection.cut); moveItems(fromParent, toParent, fromItems, toItems, get(cut));
selection.resetCopied(); selection.resetCopied();
} }
} }

View File

@@ -212,6 +212,8 @@ export class Selection {
} }
export const selection = new Selection(); export const selection = new Selection();
export const copied = selection.copied;
export const cut = selection.cut;
export function applyToOrderedItemsFromFile( export function applyToOrderedItemsFromFile(
selectedItems: ListItem[], selectedItems: ListItem[],