Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Speaker modal: revert outer wrapper + scrollToSegmentIndex + highlightSpeakerInTranscript to literal v0.8.21-alpha — last resort after multiple fix attempts kept introducing fresh bugs in the modal-panel-primitive variant; the modal-panel + modal-content combination interacted badly with virtualScroll's ResizeObserver in ways that I couldn't fix without rebuilding the primitive's height semantics; the pragmatic answer is to NOT use the modal-overlay / modal-panel primitives on this particular modal; reverted to the exact v0.8.21 wrapper markup (fixed inset-0 bg-black/70 backdrop-blur + h-[85vh] panel) which was the published version the user remembers working; the inner buttons / fields / footer still use design-system primitives (btn--primary, btn--ghost, etc.) so the visual language is consistent with the rest of the app — only the OUTER chrome (overlay + panel sizing) reverts; scrollToSegmentIndex is back to its 2-line v0.8.21 form (no querySelector / scrollIntoView / nextTick / RAF / suppression flag gymnastics — all of which were workarounds for the broken-height problem and introduced their own bugs once the height was fixed); highlightSpeakerInTranscript reverted to its 'if a group is already visible, just set currentSpeakerGroupIndex and don't scroll; otherwise pick nearest from visible center and scroll to it' behavior — that was the published v0.8.21 logic and was the right semantics; the recent change I made to 'always scroll' was treating a symptom (the visible-range check returning wrong answers because containerHeight was unstable) not a cause

Murtaza Nasir8b279fb379b6
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 15a13b9a..26037659 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -2238,59 +2238,16 @@ document.addEventListener('DOMContentLoaded', async () => {
});
// Helper to scroll to a segment by index (for speaker navigation).
- //
- // The flicker the user was seeing comes from smooth-scrolling
- // a virtual scroll container where item heights vary. The
- // browser animates scrollTop continuously; every frame the
- // scroll event fires, visibleRange recomputes, and different
- // items render. When their REAL heights differ from the
- // fixed 52 px estimate, the total scrollHeight changes mid-
- // animation, the relative scroll position shifts, the smooth
- // scroll target snaps to a slightly different place, and the
- // viewport visibly stutters until the animation ends.
- //
- // The fix is to NOT smooth-scroll the virtual scroll itself.
- // Instead:
- // 1. Instant jump via virtualScroll.scrollToIndex('auto')
- // to get the target's DOM node into the rendered window.
- // This fires ONE scroll event, range recomputes ONCE.
- // 2. Two RAFs to let Vue's reactive update + the browser's
- // paint pass finish, so the target node exists with its
- // measured height.
- // 3. scrollIntoView({block:'center', behavior:'smooth'}) on
- // the real element. Because the target is already in the
- // rendered window, the smooth animation just moves the
- // element into the centre of the viewport — visibleRange
- // doesn't change during this final adjustment (the
- // animation is small enough that the same items remain
- // visible), so no flicker.
- //
- // No scroll-event suppression — that interferes with the
- // user's own mouse-wheel scrolling. The native scroll path
- // stays plain virtualScroll.onScroll.
+ // EXACT v0.8.21-alpha implementation, restored after weeks of
+ // overengineering by me. With the modal wrapper reverted to
+ // its original 'h-[85vh] flex flex-col' markup, this one-line
+ // works the same way it always did.
const scrollToSegmentIndex = (index) => {
- const inModal = showSpeakerModal.value;
- const vs = inModal ? speakerModalVirtualScroll : mainTranscriptVirtualScroll;
- const containerRef = inModal ? speakerModalTranscriptRef : mainTranscriptRef;
- if (!containerRef.value) return;
-
- // Step 1: instant rough position (offset upward so the
- // smooth fine-tune is a small downward movement, not a
- // large jump that would re-trigger range changes).
- vs.scrollToIndex(Math.max(0, index - 5), 'auto');
-
- // Step 2 + 3: after the visible range paints, smooth-
- // scroll the actual DOM node to centre. Two RAFs because
- // Vue's render is one microtask + browser paint is one
- // animation frame.
- requestAnimationFrame(() => {
- requestAnimationFrame(() => {
- const target = containerRef.value && containerRef.value.querySelector(`[data-segment-index="${index}"]`);
- if (target) {
- target.scrollIntoView({ block: 'center', behavior: 'smooth' });
- }
- });
- });
+ if (showSpeakerModal.value) {
+ speakerModalVirtualScroll.scrollToIndex(index, 'smooth');
+ } else {
+ mainTranscriptVirtualScroll.scrollToIndex(index, 'smooth');
+ }
};
// Add scrollToSegmentIndex to utils for composables that need it
diff --git a/static/js/modules/composables/speakers.js b/static/js/modules/composables/speakers.js
index 200f7d17..a9a1009f 100644
--- a/static/js/modules/composables/speakers.js
+++ b/static/js/modules/composables/speakers.js
@@ -604,37 +604,49 @@ export function useSpeakers(state, utils, processedTranscription) {
speakerGroups.value = findSpeakerGroups(speakerId);
if (speakerGroups.value.length > 0) {
- // Pick the nearest group to whatever's currently in view
- // (so quickly cycling between speakers feels local) and
- // ALWAYS scroll to it. The previous "if it's already in
- // the visible range, don't scroll" optimization fought
- // the user's expectation: clicking into a speaker's
- // textbox should snap to that speaker's first
- // occurrence, not silently leave the viewport where it
- // happened to be. With the smooth-scroll polish in
- // scrollToSegmentIndex the scroll feels natural even
- // when the target was already on screen — it just
- // re-centres the row, which makes the highlight obvious.
+ // Get the current visible range from the virtual scroll
const visibleRange = utils.getSpeakerModalVisibleRange ? utils.getSpeakerModalVisibleRange() : null;
- const visibleCenter = visibleRange
- ? Math.floor((visibleRange.start + visibleRange.end) / 2)
- : 0;
-
- let nearestIndex = 0;
- let nearestDistance = Infinity;
- speakerGroups.value.forEach((group, index) => {
- const distance = Math.abs(group.startIndex - visibleCenter);
- if (distance < nearestDistance) {
- nearestDistance = distance;
- nearestIndex = index;
- }
- });
-
- currentSpeakerGroupIndex.value = nearestIndex;
- const nearestGroup = speakerGroups.value[nearestIndex];
- if (nearestGroup && typeof nearestGroup.startIndex === 'number' && utils.scrollToSegmentIndex) {
- utils.scrollToSegmentIndex(nearestGroup.startIndex);
+ if (visibleRange) {
+ const { start: visibleStart, end: visibleEnd } = visibleRange;
+ const visibleCenter = Math.floor((visibleStart + visibleEnd) / 2);
+
+ // Check if any group is already visible
+ const visibleGroupIndex = speakerGroups.value.findIndex(group =>
+ group.startIndex >= visibleStart && group.startIndex < visibleEnd
+ );
+
+ if (visibleGroupIndex !== -1) {
+ // A group is already visible, just set it as current (no scroll needed)
+ currentSpeakerGroupIndex.value = visibleGroupIndex;
+ } else {
+ // No group visible - find the nearest group to the visible center
+ let nearestIndex = 0;
+ let nearestDistance = Infinity;
+
+ speakerGroups.value.forEach((group, index) => {
+ const distance = Math.abs(group.startIndex - visibleCenter);
+ if (distance < nearestDistance) {
+ nearestDistance = distance;
+ nearestIndex = index;
+ }
+ });
+
+ currentSpeakerGroupIndex.value = nearestIndex;
+
+ // Scroll to the nearest group
+ const nearestGroup = speakerGroups.value[nearestIndex];
+ if (nearestGroup && typeof nearestGroup.startIndex === 'number' && utils.scrollToSegmentIndex) {
+ utils.scrollToSegmentIndex(nearestGroup.startIndex);
+ }
+ }
+ } else {
+ // Fallback: no visible range available, scroll to first group
+ currentSpeakerGroupIndex.value = 0;
+ const firstGroup = speakerGroups.value[0];
+ if (firstGroup && typeof firstGroup.startIndex === 'number' && utils.scrollToSegmentIndex) {
+ utils.scrollToSegmentIndex(firstGroup.startIndex);
+ }
}
} else {
currentSpeakerGroupIndex.value = -1;
diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.html
index b72245a1..c0b92942 100644
--- a/templates/modals/speaker-modal.html
+++ b/templates/modals/speaker-modal.html
@@ -1,15 +1,19 @@
-<!-- Speaker Identification Modal (design system v1).
- IMPORTANT: explicit height: 85vh (was h-[85vh] in the original
- speaker-modal pre-design-system migration). The .modal-panel
- primitive uses max-height: 88vh which lets the panel SHRINK to its
- content — and when content shrinks below the viewport, the
- transcript pane's clientHeight changes too. That was the root cause
- of the scroll oscillation; the ResizeObserver fired on every
- content change, the visibleRange recomputed, different items
- rendered, height changed again, repeat. Locking the modal to a
- fixed height stops the feedback loop. -->
-<div v-if="showSpeakerModal" @click.self="closeSpeakerModal" class="modal-overlay">
- <div @click="closeSpeakerSuggestionsOnClick" class="modal-panel modal-panel--xl" style="height: 90vh;">
+<!-- Speaker Identification Modal.
+ Outer wrapper deliberately kept as raw Tailwind (fixed inset-0 +
+ custom h-[85vh] panel), NOT migrated to modal-overlay/.modal-panel
+ primitives. The primitive variant kept introducing layout bugs in
+ the virtual-scroll'd transcript pane (.modal-panel's max-height
+ vs fixed-height, the stacked .modal-content scrollable container,
+ the panel shrinking to content height — all symptoms of the same
+ underlying mismatch between the column-flex primitive and this
+ modal's specific need for a STABLE-height transcript pane so
+ virtualScroll's ResizeObserver doesn't oscillate). Reverted to
+ the exact v0.8.21-alpha wrapper markup that's known to work. The
+ inner buttons / fields / footer still use the design-system
+ primitives (btn, btn--primary, etc.) so visual consistency with
+ the rest of the app is preserved. -->
+<div v-if="showSpeakerModal" @click.self="closeSpeakerModal" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 p-2 sm:p-4 backdrop-blur-sm">
+ <div @click="closeSpeakerSuggestionsOnClick" class="bg-[var(--bg-secondary)] rounded-xl shadow-2xl w-full max-w-4xl flex flex-col h-[95vh] sm:h-[85vh]">
<div class="modal-header">
<h3 class="modal-title" v-text="t('modal.identifySpeakers')"></h3>
<button @click="closeSpeakerModal" class="modal-close" :title="t('buttons.close')"><i class="fas fa-times"></i></button>