Skip to content

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

Python

Fix virtual scroll issues in ASR editor and speaker modals

Murtaza Nasir8ed7f8c7d277
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index f7dcb718..4c2f5db7 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -1063,6 +1063,8 @@ document.addEventListener('DOMContentLoaded', async () => {
// Add scrollToSegmentIndex to utils for composables that need it
utils.scrollToSegmentIndex = scrollToSegmentIndex;
utils.resetModalAudioState = resetModalAudioState;
+ utils.resetAsrEditorScroll = () => asrEditorVirtualScroll.reset();
+ utils.resetSpeakerModalScroll = () => speakerModalVirtualScroll.reset();
// Speakers composable needs processedTranscription and scrollToSegmentIndex
const speakersComposable = useSpeakers(state, utils, processedTranscription);
diff --git a/static/js/modules/composables/speakers.js b/static/js/modules/composables/speakers.js
index 57e5d479..4bb2d36b 100644
--- a/static/js/modules/composables/speakers.js
+++ b/static/js/modules/composables/speakers.js
@@ -91,6 +91,11 @@ export function useSpeakers(state, utils, processedTranscription) {
showSpeakerModal.value = true;
+ // Reset virtual scroll state for fresh modal render
+ if (utils.resetSpeakerModalScroll) {
+ utils.resetSpeakerModalScroll();
+ }
+
// Load voice-based suggestions if embeddings are available
loadVoiceSuggestions();
};
diff --git a/static/js/modules/composables/transcription.js b/static/js/modules/composables/transcription.js
index 010cf550..5bad1c87 100644
--- a/static/js/modules/composables/transcription.js
+++ b/static/js/modules/composables/transcription.js
@@ -86,6 +86,11 @@ export function useTranscription(state, utils) {
}));
showAsrEditorModal.value = true;
+
+ // Reset virtual scroll state for fresh modal render
+ if (utils.resetAsrEditorScroll) {
+ utils.resetAsrEditorScroll();
+ }
} catch (e) {
console.error("Could not parse transcription as JSON for ASR editor:", e);
setGlobalError("This transcription is not in the correct format for the ASR editor.");
@@ -198,9 +203,10 @@ export function useTranscription(state, utils) {
const updateDropdownPosition = (index) => {
nextTick(() => {
- const rows = document.querySelectorAll('.asr-editor-table tbody tr');
- if (rows[index]) {
- const cell = rows[index].querySelector('td:first-child');
+ // Find row by data attribute to work correctly with virtual scrolling
+ const row = document.querySelector(`.asr-editor-table tbody tr[data-segment-index="${index}"]`);
+ if (row) {
+ const cell = row.querySelector('td:first-child');
if (cell) {
const rect = cell.getBoundingClientRect();
const viewportHeight = window.innerHeight;
diff --git a/static/js/modules/composables/virtualScroll.js b/static/js/modules/composables/virtualScroll.js
index 7a1bbcb1..620feed2 100644
--- a/static/js/modules/composables/virtualScroll.js
+++ b/static/js/modules/composables/virtualScroll.js
@@ -140,6 +140,19 @@ export function useVirtualScroll(options) {
scrollToIndex(targetIndex, 'smooth');
};
+ // Reset scroll state (call when modal opens or items change completely)
+ const reset = () => {
+ scrollTop.value = 0;
+ isInitialized.value = false;
+ // Re-initialize after a tick to allow DOM to render
+ Vue.nextTick(() => {
+ if (containerRef.value) {
+ containerRef.value.scrollTop = 0;
+ initializeContainer();
+ }
+ });
+ };
+
// Watch for containerRef changes and initialize
watch(containerRef, (newRef) => {
if (newRef) {
@@ -171,6 +184,9 @@ export function useVirtualScroll(options) {
scrollToIndex,
scrollToIndexIfNeeded,
+ // Control
+ reset,
+
// State (for debugging/testing)
scrollTop,
containerHeight,
diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.html
index 5c0a4bf6..c2f04edd 100644
--- a/templates/modals/asr-editor-modal.html
+++ b/templates/modals/asr-editor-modal.html
@@ -74,7 +74,7 @@
<!-- Virtual scroll spacer (top) -->
<tr v-if="asrEditorSpacerBefore > 0"><td colspan="5" :style="{ height: asrEditorSpacerBefore + 'px', padding: 0 }"></td></tr>
- <tr v-for="segment in asrEditorVisibleSegments" :key="`asr-${segment._originalIndex}-${segment.start_time}`" class="hover:bg-[var(--bg-tertiary)] transition-colors border-b border-[var(--border-primary)]">
+ <tr v-for="segment in asrEditorVisibleSegments" :key="`asr-${segment._originalIndex}-${segment.start_time}`" :data-segment-index="segment._originalIndex" class="hover:bg-[var(--bg-tertiary)] transition-colors border-b border-[var(--border-primary)]">
<td class="border-r border-[var(--border-primary)] align-middle">
<div class="relative h-full">
<div class="flex items-center h-full">