Skip to content

TT-7625 fix: keep PBT segment boundaries flush when dragged after playback - #524

Open
nabalone wants to merge 1 commit into
developfrom
TT-7625_pbt-segment-boundaries
Open

TT-7625 fix: keep PBT segment boundaries flush when dragged after playback#524
nabalone wants to merge 1 commit into
developfrom
TT-7625_pbt-segment-boundaries

Conversation

@nabalone

Copy link
Copy Markdown
Collaborator

Fixes TT-7625PBT segments can overlap and disconnect.

Problem

On the Phrase Back Translate step: with multiple segments, click Start Recording, let the first segment auto-play, then drag the boundary between two segments. The adjoining segment's boundary does not follow — the segments overlap or leave a gap.

Root cause

useWaveSurferRegions already keeps segment maps contiguous: on region-update / region-updated it clamps the dragged boundary and shifts the single adjacent neighbor's shared boundary to follow (constrainResizedRegion). Both handlers gate that on !updatingRef.current — a latch that means "we are moving region bounds programmatically, ignore this event".

wsPlayRegion set that latch and released it only on its early-return path (region not found). Every successful region play left it stuck true for the rest of the session.

PBT (like Careful Speech) passes forceRegionOnly, so WSAudioPlayer.handlePlayStatus routes every play through wsPlayRegion. Once the first segment auto-played, the clamp never ran again — which is exactly why the other waveforms (which play the whole file) still behave correctly.

Change

  • wsPlayRegion now releases updatingRef in a finally, so the latch covers only its synchronous body. The shared-boundary behavior PBT gets is the same code path Mark Verses already uses — no new special case.
  • Extracted the clamp math out of the hook into utils/sharedSegmentBoundary.ts (clampSharedBoundary) with unit tests, so the "end of one segment is the start of the next" rule is verifiable on its own. constrainResizedRegion is now just the wavesurfer plumbing around it.

Note: the regions plugin emits region-update / region-updated only from drag/resize (_onUpdate), never from setOptions, so releasing the latch cannot let programmatic bound/color changes be mistaken for a user drag.

Test plan

  • npx jest in src/renderer — 164 suites, 1317 tests pass, including the new sharedSegmentBoundary suite (9 tests) and the full PassageDetailMarkVerses suite (18 tests, re-run in isolation before and after the change).
  • npx tsc --noEmit clean; eslint + prettier clean on the touched files.
  • Manual (recommended before merge): PBT step with multiple segments → Start Recording → after the first segment auto-plays, drag a boundary. The neighbor boundary should follow, segments stay flush, and neither segment can be pushed past its neighbor's far edge. Same check on Careful Speech and Mark Verses for no regression.

🤖 Generated with Claude Code

…yback

The shared-boundary clamp in useWaveSurferRegions is gated on updatingRef,
a latch meant to mark "we are moving region bounds programmatically".
wsPlayRegion set that latch but only released it on its early-return path,
so any successful region play left it stuck true for the rest of the
session. Phrase Back Translate (and Careful Speech) pass forceRegionOnly,
which routes every play through wsPlayRegion, so once the first segment
auto-played the clamp stopped running: dragging a boundary moved only the
dragged segment and left its neighbor behind, so the two overlapped or
disconnected. Release the latch in a finally so it covers just the
synchronous body.

Also extract the clamp math into utils/sharedSegmentBoundary.ts with unit
tests, so the "end of one segment is the start of the next" rule the other
waveforms already follow is verifiable on its own.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@nabalone
nabalone force-pushed the TT-7625_pbt-segment-boundaries branch from 61040e4 to 0afb870 Compare August 21, 2026 21:04
@nabalone
nabalone marked this pull request as ready for review August 21, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant