Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/lib/components/SceneCardsView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,17 @@
? 'INT · EXT'
: ''}
{@const timeWord = (card.time ?? '').toUpperCase()}
<!-- Drag state is tracked by 1-based scene ORDINAL (sceneOrder + 1),
not the displayed sceneNumber. sceneNumber is offset by the
document's scene_number_start (a co-writing feature), whereas
the drop-target detection and reorderScene both work in plain
positional 1-based scene order. Mixing the two spaces silently
broke drag-reorder for any file whose numbering didn't start
at 1. -->
<div
class="card scene-card"
class:dragging={dragFromScene === card.sceneNumber}
class:drop-target={dropTargetScene === card.sceneNumber}
class:dragging={dragFromScene === card.sceneOrder + 1}
class:drop-target={dropTargetScene === card.sceneOrder + 1}
class:skeleton={isSkeleton}
data-time={timeWord}
animate:flip={{ duration: 450, easing: cubicInOut }}
Expand All @@ -1022,7 +1029,7 @@
class="card-gutter"
class:disabled={groupByLocation}
onmousedown={(e: MouseEvent) => {
if (!groupByLocation) startDrag(e, card.sceneNumber);
if (!groupByLocation) startDrag(e, card.sceneOrder + 1);
}}
role="button"
tabindex="-1"
Expand Down
38 changes: 32 additions & 6 deletions src/lib/components/SceneNavigator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,27 @@
tr.scrollIntoView();
view.dispatch(tr);

// Remap scene_cards indices to follow the reordered scenes — same as
// SceneCardsView.reorderScene. scene_index is positional, so without
// this a moved scene would pick up its old slot's description/notes.
if (documentStore.document) {
for (const card of documentStore.activeSceneCards) {
if (card.scene_index === fromIdx) {
card.scene_index = toIdx;
} else if (fromIdx < toIdx) {
// Moving forward: scenes between from+1 and to shift down by 1
if (card.scene_index > fromIdx && card.scene_index <= toIdx) {
card.scene_index--;
}
} else {
// Moving backward: scenes between to and from-1 shift up by 1
if (card.scene_index >= toIdx && card.scene_index < fromIdx) {
card.scene_index++;
}
}
}
}

// Mark document dirty
documentStore.markDirty();

Expand Down Expand Up @@ -595,22 +616,27 @@
<li
class="scene-li"
class:active={isActive}
class:drop-above={dropTargetScene === scene.number &&
class:drop-above={dropTargetScene === sceneArrayIdx + 1 &&
dragFromScene !== null &&
dragFromScene > scene.number}
class:drop-below={dropTargetScene === scene.number &&
dragFromScene > sceneArrayIdx + 1}
class:drop-below={dropTargetScene === sceneArrayIdx + 1 &&
dragFromScene !== null &&
dragFromScene < scene.number}
class:dragging={dragFromScene === scene.number}
dragFromScene < sceneArrayIdx + 1}
class:dragging={dragFromScene === sceneArrayIdx + 1}
>
{#if isActiveEpisode}
<!-- Drag handle only on the active episode — drag-reorder
needs editorStore.view, which only points at the active
episode's content. Cross-episode reordering is a
follow-up. (#156) -->
<!-- Drag uses the 1-based scene ORDINAL (position in the list),
not scene.number, which is offset by scene_number_start.
reorderScene + the drop detection both work in positional
order; passing the offset number broke reorder for any
file not starting at scene 1. -->
<span
class="drag-handle"
onmousedown={(e: MouseEvent) => startDrag(e, scene.number)}
onmousedown={(e: MouseEvent) => startDrag(e, sceneArrayIdx + 1)}
role="button"
tabindex="-1"
aria-label="Drag to reorder scene {scene.number}"
Expand Down
Loading