Skip to content

Commit 352637a

Browse files
Recenter on showMorphology toggle
1 parent 20aeccd commit 352637a

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/__tests__/components/ContinuousView.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,21 @@ describe('ContinuousView scroll behavior', () => {
11251125
);
11261126
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
11271127
});
1128+
1129+
it('re-centers once when showMorphology toggles', () => {
1130+
// Morpheme rows beneath tokens can widen phrase boxes, shifting the strip layout, so the
1131+
// focused group must be snapped back to center when the toggle flips.
1132+
const book = makeBook();
1133+
const props = requiredProps(book, { focusedTokenRef: 'tok-0' });
1134+
const { rerender } = render(<ContinuousView {...props} />, withAnalysisStore);
1135+
scrollIntoViewMock.mockClear();
1136+
1137+
rerender(<ContinuousView {...props} showMorphology />);
1138+
expect(scrollIntoViewMock).toHaveBeenCalledWith(
1139+
expect.objectContaining({ behavior: 'auto', inline: 'center' }),
1140+
);
1141+
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
1142+
});
11281143
});
11291144

11301145
// ---------------------------------------------------------------------------

src/components/ContinuousView.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,17 +583,18 @@ export default function ContinuousView({
583583
// eslint-disable-next-line react-hooks/exhaustive-deps
584584
}, [committedActiveSegmentId]);
585585

586-
// Re-center the focused group when a view option toggles. Toggling `simplifyPhrases` changes
587-
// the strip's layout, so the previously-centered group may drift off-center; snap it back into
588-
// view. `hideInactiveLinkButtons` is excluded: inactive link slots now reserve their space even
589-
// when hidden (`opacity: 0`; clickability is guarded at the button level), so toggling it does
590-
// not shift the layout.
586+
// Re-center the focused group when a view option toggles. Toggling `simplifyPhrases` or
587+
// `showMorphology` changes the strip's layout (morpheme rows can widen phrase boxes), so the
588+
// previously-centered group may drift off-center; snap it back into view.
589+
// `hideInactiveLinkButtons` is excluded: inactive link slots now reserve their space even when
590+
// hidden (`opacity: 0`; clickability is guarded at the button level), so toggling it does not
591+
// shift the layout.
591592
useEffect(() => {
592593
centerGroup(focusPhraseIndex, 'auto');
593594
// focusPhraseIndex is intentionally excluded: it has its own scroll effect above. This effect
594595
// only re-centers in response to layout-affecting option toggles. centerGroup is stable.
595596
// eslint-disable-next-line react-hooks/exhaustive-deps
596-
}, [simplifyPhrases]);
597+
}, [simplifyPhrases, showMorphology]);
597598

598599
// When entering edit or confirm-unlink mode, smooth-scroll to the first group of the active
599600
// phrase by notifying the parent of the new focused token. Scroll then follows automatically

0 commit comments

Comments
 (0)