Skip to content

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

Python

Add scroll memory, save-without-closing, Ctrl+S, and double-click-to-edit to the ASR transcript editor

Murtaza Nasirdfd1a0c3f50b
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 99f04a75..55870103 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -610,6 +610,7 @@ document.addEventListener('DOMContentLoaded', async () => {
const speakerModalTranscriptRef = ref(null);
const mainTranscriptRef = ref(null);
const asrEditorRef = ref(null);
+ const asrEditorSaveFlash = ref(false); // Brief "Saved" indicator after Save (without close)
// --- Computed properties needed by composables ---
const isMobileScreen = computed(() => windowWidth.value < 1024);
@@ -762,7 +763,7 @@ document.addEventListener('DOMContentLoaded', async () => {
currentSpeakerGroupIndex, speakerGroups,
// Virtual Scroll
- speakerModalTranscriptRef, mainTranscriptRef, asrEditorRef
+ speakerModalTranscriptRef, mainTranscriptRef, asrEditorRef, asrEditorSaveFlash
};
// =========================================================================
@@ -1412,6 +1413,12 @@ document.addEventListener('DOMContentLoaded', async () => {
utils.scrollToSegmentIndex = scrollToSegmentIndex;
utils.resetModalAudioState = resetModalAudioState;
utils.resetAsrEditorScroll = () => asrEditorVirtualScroll.reset();
+ utils.scrollAsrEditorToIndex = (index) => asrEditorVirtualScroll.scrollToIndex(index, 'auto');
+ utils.setAsrEditorScrollTop = (scrollTop) => {
+ if (asrEditorRef.value) {
+ asrEditorRef.value.scrollTop = scrollTop;
+ }
+ };
utils.resetSpeakerModalScroll = () => speakerModalVirtualScroll.reset();
utils.getSpeakerModalVisibleRange = () => speakerModalVirtualScroll.visibleRange.value;
@@ -2580,6 +2587,7 @@ document.addEventListener('DOMContentLoaded', async () => {
speakerModalTranscriptRef,
mainTranscriptRef,
asrEditorRef,
+ asrEditorSaveFlash,
speakerModalVisibleSegments: speakerModalVirtualScroll.visibleItems,
speakerModalSpacerBefore: speakerModalVirtualScroll.spacerBefore,
speakerModalSpacerAfter: speakerModalVirtualScroll.spacerAfter,
diff --git a/static/js/modules/composables/transcription.js b/static/js/modules/composables/transcription.js
index 6ac52ad6..d4e2938c 100644
--- a/static/js/modules/composables/transcription.js
+++ b/static/js/modules/composables/transcription.js
@@ -3,11 +3,22 @@
* Handles ASR editor, text editor, and segment management
*/
+// Module-scoped scroll-position memory for the ASR editor. Keyed by recording
+// id so users editing a long transcript can close and reopen the modal within
+// the same session and land back where they left off. Cleared implicitly when
+// the page reloads.
+const _asrEditorScrollMemory = new Map();
+
+// Pending segment index to scroll to when the editor next opens. Used by the
+// double-click-on-simple-view-segment path. null means "restore last scroll".
+let _asrEditorPendingScrollIndex = null;
+
export function useTranscription(state, utils) {
const {
showTextEditorModal, showAsrEditorModal, selectedRecording,
editingTranscriptionContent, editingSegments, availableSpeakers,
- recordings, dropdownPositions, openAsrDropdownIndex
+ recordings, dropdownPositions, openAsrDropdownIndex,
+ asrEditorRef, asrEditorSaveFlash
} = state;
const { showToast, setGlobalError, nextTick } = utils;
@@ -87,17 +98,54 @@ export function useTranscription(state, utils) {
showAsrEditorModal.value = true;
- // Reset virtual scroll state for fresh modal render
+ // Reset virtual scroll state for fresh modal render. After it
+ // initialises, either scroll to a specific segment (when the
+ // modal was opened from a double-click on a simple-view row) or
+ // restore the last scroll position for this recording.
if (utils.resetAsrEditorScroll) {
utils.resetAsrEditorScroll();
}
+ const recordingId = selectedRecording.value.id;
+ const targetIndex = _asrEditorPendingScrollIndex;
+ _asrEditorPendingScrollIndex = null;
+ await nextTick();
+ // requestAnimationFrame defers past the virtualScroll's own
+ // post-mount initialisation tick.
+ requestAnimationFrame(() => {
+ if (targetIndex != null) {
+ if (utils.scrollAsrEditorToIndex) {
+ utils.scrollAsrEditorToIndex(targetIndex);
+ }
+ } else {
+ const saved = _asrEditorScrollMemory.get(recordingId);
+ if (saved != null && utils.setAsrEditorScrollTop) {
+ utils.setAsrEditorScrollTop(saved);
+ }
+ }
+ });
} 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.");
}
};
+ // Open the editor and scroll to a specific segment index. Used by the
+ // double-click-on-simple-view-row affordance.
+ const openAsrEditorAtSegment = (segmentIndex) => {
+ _asrEditorPendingScrollIndex = segmentIndex;
+ return openAsrEditorModal();
+ };
+
const closeAsrEditorModal = () => {
+ // Save scroll position so reopening the same recording within this
+ // session lands the user back where they were.
+ if (selectedRecording.value && asrEditorRef && asrEditorRef.value) {
+ _asrEditorScrollMemory.set(
+ selectedRecording.value.id,
+ asrEditorRef.value.scrollTop
+ );
+ }
+
// Pause any playing modal audio before closing
const modalAudio = document.querySelector('.fixed.z-50 audio') || document.querySelector('.fixed.z-50 video');
if (modalAudio) {
@@ -112,15 +160,39 @@ export function useTranscription(state, utils) {
editingSegments.value = [];
};
- const saveAsrTranscription = async () => {
+ const saveAsrTranscription = async (keepOpen = false) => {
if (!selectedRecording.value) return;
// Remove extra UI fields and save the rest
const contentToSave = JSON.stringify(editingSegments.value.map(({ id, showSuggestions, filteredSpeakers, ...rest }) => rest));
await saveTranscriptionContent(contentToSave);
- closeAsrEditorModal();
+
+ if (keepOpen) {
+ // Briefly flash a "Saved" indicator so the user knows the write
+ // succeeded without the modal closing.
+ if (asrEditorSaveFlash) {
+ asrEditorSaveFlash.value = true;
+ setTimeout(() => { asrEditorSaveFlash.value = false; }, 1800);
+ }
+ } else {
+ closeAsrEditorModal();
+ }
+ };
+
+ // Ctrl+S / Cmd+S handler -- saves without closing while the editor modal
+ // is open. preventDefault stops the browser's "save page" dialog.
+ const handleAsrEditorKeydown = (event) => {
+ if (!showAsrEditorModal.value) return;
+ const isSaveShortcut = (event.ctrlKey || event.metaKey) && (event.key === 's' || event.key === 'S');
+ if (isSaveShortcut) {
+ event.preventDefault();
+ saveAsrTranscription(true);
+ }
};
+ if (typeof window !== 'undefined') {
+ window.addEventListener('keydown', handleAsrEditorKeydown);
+ }
// =========================================
// Segment Management
@@ -457,6 +529,7 @@ export function useTranscription(state, utils) {
// ASR editor
openAsrEditorModal,
+ openAsrEditorAtSegment,
closeAsrEditorModal,
saveAsrTranscription,
diff --git a/templates/components/detail/desktop-transcription-panel.html b/templates/components/detail/desktop-transcription-panel.html
index 66b9e9b5..4f895fc3 100644
--- a/templates/components/detail/desktop-transcription-panel.html
+++ b/templates/components/detail/desktop-transcription-panel.html
@@ -207,6 +207,8 @@
:key="`seg-${index}-${segment.startTime}`"
:class="['speaker-segment', { 'active-playing-segment': currentPlayingSegmentIndex === index }]"
@click="seekAudioFromEvent"
+ @dblclick.stop="openAsrEditorAtSegment(index)"
+ :title="'Double-click to edit this segment'"
:data-start-time="segment.startTime"
:data-segment-index="index">
<div v-if="segment.showSpeaker" class="speaker-segment-header">
@@ -229,6 +231,8 @@
:key="`seg-${index}-${segment.startTime}`"
:class="['transcript-segment cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors', { 'active-playing-segment': currentPlayingSegmentIndex === index }]"
@click="seekAudioFromEvent"
+ @dblclick.stop="openAsrEditorAtSegment(index)"
+ :title="'Double-click to edit this segment'"
:data-start-time="segment.startTime"
:data-segment-index="index">
<span v-if="showTimestampsSimpleView"
diff --git a/templates/components/detail/mobile-transcript-panel.html b/templates/components/detail/mobile-transcript-panel.html
index 4074189c..fb58d9ef 100644
--- a/templates/components/detail/mobile-transcript-panel.html
+++ b/templates/components/detail/mobile-transcript-panel.html
@@ -104,7 +104,7 @@
<div v-if="selectedRecording.transcription && !processedTranscription.isError">
<div v-if="!processedTranscription.hasDialogue || transcriptionViewMode === 'simple'" class="transcription-simple-view">
<div v-if="processedTranscription.hasDialogue">
- <div v-for="(segment, index) in processedTranscription.simpleSegments" :key="`seg-${index}-${segment.startTime}`" :class="['speaker-segment', { 'active-playing-segment': currentPlayingSegmentIndex === index }]" @click="seekAudioFromEvent" :data-start-time="segment.startTime" :data-segment-index="index">
+ <div v-for="(segment, index) in processedTranscription.simpleSegments" :key="`seg-${index}-${segment.startTime}`" :class="['speaker-segment', { 'active-playing-segment': currentPlayingSegmentIndex === index }]" @click="seekAudioFromEvent" @dblclick.stop="openAsrEditorAtSegment(index)" :data-start-time="segment.startTime" :data-segment-index="index">
<div v-if="segment.showSpeaker" class="speaker-segment-header">
<div :class="['speaker-tablet', segment.color]">${segment.speaker}</div>
<span v-if="showTimestampsSimpleView" class="speaker-segment-timestamp">${ formatTimestamp(segment.startTime) }</span>
@@ -114,7 +114,7 @@
</div>
<div v-else>
<div v-if="processedTranscription.simpleSegments && processedTranscription.simpleSegments.length > 0">
- <div v-for="(segment, index) in processedTranscription.simpleSegments" :key="`seg-${index}-${segment.startTime}`" :class="['transcript-segment cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors', { 'active-playing-segment': currentPlayingSegmentIndex === index }]" @click="seekAudioFromEvent" :data-start-time="segment.startTime" :data-segment-index="index"><span v-if="showTimestampsSimpleView" class="speaker-segment-timestamp speaker-segment-timestamp--inline">${ formatTimestamp(segment.startTime) }</span>${segment.sentence}</div>
+ <div v-for="(segment, index) in processedTranscription.simpleSegments" :key="`seg-${index}-${segment.startTime}`" :class="['transcript-segment cursor-pointer hover:bg-[var(--bg-accent-hover)] p-2 rounded transition-colors', { 'active-playing-segment': currentPlayingSegmentIndex === index }]" @click="seekAudioFromEvent" @dblclick.stop="openAsrEditorAtSegment(index)" :data-start-time="segment.startTime" :data-segment-index="index"><span v-if="showTimestampsSimpleView" class="speaker-segment-timestamp speaker-segment-timestamp--inline">${ formatTimestamp(segment.startTime) }</span>${segment.sentence}</div>
</div>
<div v-else class="whitespace-pre-wrap">${processedTranscription.content}</div>
</div>
diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.html
index 97e6a3c8..6c68d82f 100644
--- a/templates/modals/asr-editor-modal.html
+++ b/templates/modals/asr-editor-modal.html
@@ -2,7 +2,14 @@
<div v-if="showAsrEditorModal" @click.self="closeAsrEditorModal" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 p-4 backdrop-blur-sm">
<div @click="closeAllSpeakerSuggestions" class="bg-[var(--bg-secondary)] rounded-xl shadow-2xl w-full max-w-6xl flex flex-col max-h-[90vh]">
<div class="p-5 border-b border-[var(--border-primary)] flex-shrink-0 flex justify-between items-center">
- <h3 class="text-xl font-bold text-[var(--text-primary)]" v-text="t('modal.editAsrTranscription')"></h3>
+ <div class="flex items-center gap-3">
+ <h3 class="text-xl font-bold text-[var(--text-primary)]" v-text="t('modal.editAsrTranscription')"></h3>
+ <span v-if="asrEditorSaveFlash"
+ class="inline-flex items-center gap-1.5 text-xs font-medium text-[var(--text-success-strong)] bg-[var(--bg-success-light)] px-2 py-1 rounded-md transition-opacity">
+ <i class="fas fa-check-circle"></i>
+ <span>Saved</span>
+ </span>
+ </div>
<button @click="closeAsrEditorModal" class="p-2 rounded-lg hover:bg-[var(--bg-tertiary)] transition-colors">
<i class="fas fa-times"></i>
</button>
@@ -146,9 +153,19 @@
</button>
</div>
</div>
- <div class="bg-[var(--bg-tertiary)] px-6 py-4 flex justify-end space-x-3 border-t border-[var(--border-primary)] flex-shrink-0 rounded-b-xl">
- <button @click="closeAsrEditorModal" class="px-4 py-2 bg-[var(--bg-secondary)] text-[var(--text-secondary)] rounded-lg border border-[var(--border-secondary)] hover:bg-[var(--bg-tertiary)]" v-text="t('common.cancel')"></button>
- <button @click="saveAsrTranscription" class="px-4 py-2 bg-[var(--bg-accent)] text-[var(--text-accent)] rounded-lg hover:bg-[var(--bg-accent-hover)]" v-text="t('buttons.saveChanges')"></button>
+ <div class="bg-[var(--bg-tertiary)] px-6 py-4 flex justify-between items-center border-t border-[var(--border-primary)] flex-shrink-0 rounded-b-xl">
+ <span class="text-xs text-[var(--text-muted)] hidden sm:inline-flex items-center gap-1.5">
+ <i class="fas fa-keyboard text-[10px]"></i>
+ <span>Ctrl+S to save</span>
+ </span>
+ <div class="flex justify-end space-x-3 ml-auto">
+ <button @click="closeAsrEditorModal" class="px-4 py-2 bg-[var(--bg-secondary)] text-[var(--text-secondary)] rounded-lg border border-[var(--border-secondary)] hover:bg-[var(--bg-tertiary)]" v-text="t('common.cancel')"></button>
+ <button @click="saveAsrTranscription(true)" class="px-4 py-2 bg-[var(--bg-secondary)] text-[var(--text-secondary)] rounded-lg border border-[var(--border-secondary)] hover:bg-[var(--bg-tertiary)] flex items-center gap-2" :title="'Save without closing (Ctrl+S)'">
+ <i class="fas fa-save text-xs"></i>
+ <span>Save</span>
+ </button>
+ <button @click="saveAsrTranscription(false)" class="px-4 py-2 bg-[var(--bg-accent)] text-[var(--text-accent)] rounded-lg hover:bg-[var(--bg-accent-hover)]" v-text="t('buttons.saveChanges')"></button>
+ </div>
</div>
</div>
</div>