Skip to content

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

Python

Sidebar: Ctrl/Cmd-click toggles and Shift-click selects a span of recordings, entering selection mode; the open recording counts as the starting point

Murtaza Nasir2eb7255def87
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index bc189816..c01728ea 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -2736,6 +2736,11 @@ document.addEventListener('DOMContentLoaded', async () => {
const speakersComposable = useSpeakers(state, utils, processedTranscription);
const speakerModalComposable = useSpeakerModal(state, utils);
+ // Recording ids in the order the sidebar shows them, for
+ // Shift-click span selection.
+ const visibleRecordingIds = computed(() =>
+ groupedRecordings.value.flatMap(group => group.items.map(r => r.id)));
+
const groupedRecordings = computed(() => {
const groups = {};
const groupDates = {}; // Track the most recent date in each group
@@ -4371,6 +4376,7 @@ document.addEventListener('DOMContentLoaded', async () => {
isMobileDevice,
processedTranscription,
groupedRecordings,
+ visibleRecordingIds,
filteredAvailableTags,
filteredTagsForFilter,
filteredSpeakersForFilter,
diff --git a/static/js/modules/composables/bulk-selection.js b/static/js/modules/composables/bulk-selection.js
index 1da48c55..005b4316 100644
--- a/static/js/modules/composables/bulk-selection.js
+++ b/static/js/modules/composables/bulk-selection.js
@@ -3,6 +3,8 @@
* Handles multi-select functionality for recordings
*/
+import { applyListClick } from '../utils/selection-range.js';
+
const { computed } = Vue;
export function useBulkSelection({
@@ -29,14 +31,45 @@ export function useBulkSelection({
};
// Methods
+ // The last recording clicked in selection mode; Shift-click selects
+ // the span from here to the clicked recording.
+ let selectionAnchorId = null;
+
const enterSelectionMode = () => {
selectionMode.value = true;
selectedRecordingIds.value = new Set();
+ selectionAnchorId = null;
};
const exitSelectionMode = () => {
selectionMode.value = false;
selectedRecordingIds.value = new Set();
+ selectionAnchorId = null;
+ };
+
+ /**
+ * A click on a recording in the sidebar list. Ctrl/Cmd-click toggles one
+ * recording and Shift-click selects a span, entering selection mode when
+ * needed; in selection mode a plain click toggles as before. Returns
+ * false when the click should open the recording instead.
+ * orderedIds: the recording ids in the order the list shows them.
+ */
+ const handleRecordingClick = (recording, event, orderedIds) => {
+ const result = applyListClick({
+ selected: selectedRecordingIds.value,
+ orderedIds: orderedIds || [],
+ anchorId: selectionAnchorId,
+ openId: selectedRecording.value ? selectedRecording.value.id : null,
+ id: recording.id,
+ ctrl: !!(event && (event.ctrlKey || event.metaKey)),
+ shift: !!(event && event.shiftKey),
+ selectionMode: selectionMode.value,
+ });
+ if (!result) return false;
+ if (result.enterMode) selectionMode.value = true;
+ selectedRecordingIds.value = result.selected;
+ selectionAnchorId = result.anchorId;
+ return true;
};
const toggleSelection = (id) => {
@@ -101,6 +134,7 @@ export function useBulkSelection({
enterSelectionMode,
exitSelectionMode,
toggleSelection,
+ handleRecordingClick,
selectAll,
clearSelection,
diff --git a/static/js/modules/utils/selection-range.js b/static/js/modules/utils/selection-range.js
new file mode 100644
index 00000000..0690c88f
--- /dev/null
+++ b/static/js/modules/utils/selection-range.js
@@ -0,0 +1,48 @@
+/**
+ * Selecting recordings in the sidebar with the keyboard modifiers of a
+ * desktop file list: Ctrl-click (Cmd-click on macOS) adds or removes one
+ * recording, Shift-click adds every recording between the last one clicked
+ * (the anchor) and this one, in the order the list shows them.
+ *
+ * Starting a selection with a modifier while a recording is open counts the
+ * open recording as already selected and as the anchor, so Shift-clicking a
+ * second recording selects the whole span between them.
+ */
+
+/**
+ * @param {object} p
+ * @param {Set} p.selected ids currently selected
+ * @param {Array} p.orderedIds ids in the order shown in the list
+ * @param {*} p.anchorId id of the last recording clicked in selection mode
+ * @param {*} p.openId id of the recording open in the detail view
+ * @param {*} p.id id of the recording clicked
+ * @param {boolean} p.ctrl Ctrl or Cmd held
+ * @param {boolean} p.shift Shift held
+ * @param {boolean} p.selectionMode
+ * @returns {null|{selected: Set, anchorId: *, enterMode: boolean}}
+ * null when the click should open the recording as usual
+ */
+export function applyListClick({ selected, orderedIds, anchorId, openId, id, ctrl, shift, selectionMode }) {
+ if (!selectionMode && !ctrl && !shift) return null;
+
+ const openVisible = openId != null && orderedIds.includes(openId);
+ const next = selectionMode ? new Set(selected) : new Set(openVisible ? [openId] : []);
+ let anchor = selectionMode ? anchorId : (openVisible ? openId : null);
+
+ if (shift && anchor != null && orderedIds.includes(anchor) && orderedIds.includes(id)) {
+ const a = orderedIds.indexOf(anchor);
+ const b = orderedIds.indexOf(id);
+ for (let i = Math.min(a, b); i <= Math.max(a, b); i++) next.add(orderedIds[i]);
+ } else if (shift) {
+ next.add(id);
+ anchor = id;
+ } else if (!selectionMode && next.has(id)) {
+ // Ctrl-clicking the open recording starts a selection holding it.
+ anchor = id;
+ } else {
+ if (next.has(id)) next.delete(id);
+ else next.add(id);
+ anchor = id;
+ }
+ return { selected: next, anchorId: anchor, enterMode: !selectionMode };
+}
diff --git a/static/js/modules/utils/selection-range.test.js b/static/js/modules/utils/selection-range.test.js
new file mode 100644
index 00000000..2cb95758
--- /dev/null
+++ b/static/js/modules/utils/selection-range.test.js
@@ -0,0 +1,74 @@
+import { describe, it, expect } from 'vitest';
+import { applyListClick } from './selection-range.js';
+
+const ids = [1, 2, 3, 4, 5, 6];
+const click = (over) => applyListClick({
+ selected: new Set(), orderedIds: ids, anchorId: null, openId: null,
+ id: 1, ctrl: false, shift: false, selectionMode: false, ...over,
+});
+const sorted = (set) => [...set].sort((a, b) => a - b);
+
+describe('applyListClick', () => {
+ it('leaves a plain click outside selection mode to open the recording', () => {
+ expect(click({ id: 3 })).toBeNull();
+ });
+
+ it('Ctrl-click starts a selection holding the open recording and the clicked one', () => {
+ const r = click({ id: 4, ctrl: true, openId: 2 });
+ expect(r.enterMode).toBe(true);
+ expect(sorted(r.selected)).toEqual([2, 4]);
+ expect(r.anchorId).toBe(4);
+ });
+
+ it('Ctrl-click with nothing open selects just the clicked recording', () => {
+ const r = click({ id: 4, ctrl: true });
+ expect(sorted(r.selected)).toEqual([4]);
+ });
+
+ it('Ctrl-clicking the open recording starts a selection holding it', () => {
+ const r = click({ id: 2, ctrl: true, openId: 2 });
+ expect(sorted(r.selected)).toEqual([2]);
+ });
+
+ it('Shift-click from the open recording selects the span between them', () => {
+ const r = click({ id: 5, shift: true, openId: 2 });
+ expect(sorted(r.selected)).toEqual([2, 3, 4, 5]);
+ expect(r.anchorId).toBe(2);
+ });
+
+ it('two Shift-clicks with nothing open select the span between them', () => {
+ const first = click({ id: 2, shift: true });
+ expect(sorted(first.selected)).toEqual([2]);
+ const second = applyListClick({ selected: first.selected, orderedIds: ids, anchorId: first.anchorId,
+ openId: null, id: 5, ctrl: false, shift: true, selectionMode: true });
+ expect(sorted(second.selected)).toEqual([2, 3, 4, 5]);
+ });
+
+ it('a span upwards works and keeps earlier selections', () => {
+ const r = applyListClick({ selected: new Set([6]), orderedIds: ids, anchorId: 4, openId: null,
+ id: 1, ctrl: false, shift: true, selectionMode: true });
+ expect(sorted(r.selected)).toEqual([1, 2, 3, 4, 6]);
+ expect(r.anchorId).toBe(4);
+ });
+
+ it('Ctrl-click in selection mode toggles one recording and moves the anchor', () => {
+ const r = applyListClick({ selected: new Set([1, 3]), orderedIds: ids, anchorId: 1, openId: null,
+ id: 3, ctrl: true, shift: false, selectionMode: true });
+ expect(sorted(r.selected)).toEqual([1]);
+ expect(r.anchorId).toBe(3);
+ expect(r.enterMode).toBe(false);
+ });
+
+ it('a plain click in selection mode toggles, as before', () => {
+ const r = applyListClick({ selected: new Set([2]), orderedIds: ids, anchorId: 2, openId: null,
+ id: 5, ctrl: false, shift: false, selectionMode: true });
+ expect(sorted(r.selected)).toEqual([2, 5]);
+ });
+
+ it('an anchor no longer in the list falls back to selecting the clicked recording', () => {
+ const r = applyListClick({ selected: new Set(), orderedIds: ids, anchorId: 99, openId: null,
+ id: 3, ctrl: false, shift: true, selectionMode: true });
+ expect(sorted(r.selected)).toEqual([3]);
+ expect(r.anchorId).toBe(3);
+ });
+});
diff --git a/static/locales/de.json b/static/locales/de.json
index f1315a73..d69701ac 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -392,7 +392,8 @@
"exitSelection": "Auswahlmodus beenden",
"reprocess": "Neu verarbeiten",
"selectedCount": "{{count}} ausgewählt",
- "star": "Markieren"
+ "star": "Markieren",
+ "selectMultipleHint": "Mehrere auswählen (oder Aufnahmen in der Liste mit Strg-Klick / Umschalt-Klick auswählen)"
},
"bulkReprocessModal": {
"fullTranscription": "Vollständige Transkription",
diff --git a/static/locales/en.json b/static/locales/en.json
index c0fde4b8..f853a15d 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -392,7 +392,8 @@
"exitSelection": "Exit selection mode",
"reprocess": "Reprocess",
"selectedCount": "{{count}} selected",
- "star": "Star"
+ "star": "Star",
+ "selectMultipleHint": "Select multiple (or Ctrl-click / Shift-click recordings in the list)"
},
"bulkReprocessModal": {
"fullTranscription": "Full Transcription",
diff --git a/static/locales/es.json b/static/locales/es.json
index e18f2369..b0ec07e1 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -392,7 +392,8 @@
"exitSelection": "Salir del modo de selección",
"reprocess": "Reprocesar",
"selectedCount": "{{count}} seleccionados",
- "star": "Destacar"
+ "star": "Destacar",
+ "selectMultipleHint": "Seleccionar varias (o Ctrl-clic / Mayús-clic en las grabaciones de la lista)"
},
"bulkReprocessModal": {
"fullTranscription": "Transcripción completa",
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 31057486..159100ab 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -392,7 +392,8 @@
"exitSelection": "Quitter le mode sélection",
"reprocess": "Retraiter",
"selectedCount": "{{count}} sélectionnés",
- "star": "Favoris"
+ "star": "Favoris",
+ "selectMultipleHint": "Sélection multiple (ou Ctrl-clic / Maj-clic sur les enregistrements de la liste)"
},
"bulkReprocessModal": {
"fullTranscription": "Transcription complète",
diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.json
index c586e48c..77ff17e4 100644
--- a/static/locales/pt-BR.json
+++ b/static/locales/pt-BR.json
@@ -392,7 +392,8 @@
"exitSelection": "Sair do modo de seleção",
"reprocess": "Reprocessar",
"selectedCount": "{{count}} selecionados",
- "star": "Favoritar"
+ "star": "Favoritar",
+ "selectMultipleHint": "Selecionar várias (ou Ctrl-clique / Shift-clique nas gravações da lista)"
},
"bulkReprocessModal": {
"fullTranscription": "Transcrição completa",
diff --git a/static/locales/ru.json b/static/locales/ru.json
index ee54a389..97c69a9f 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -392,7 +392,8 @@
"exitSelection": "Выйти из режима выбора",
"reprocess": "Повторить",
"selectedCount": "Выбрано: {{count}}",
- "star": "Избранное"
+ "star": "Избранное",
+ "selectMultipleHint": "Выбрать несколько (или Ctrl-щелчок / Shift-щелчок по записям в списке)"
},
"bulkReprocessModal": {
"fullTranscription": "Полная транскрипция",
diff --git a/static/locales/zh.json b/static/locales/zh.json
index ac196c35..5b2e5f72 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -392,7 +392,8 @@
"exitSelection": "退出选择模式",
"reprocess": "重新处理",
"selectedCount": "已选择 {{count}} 项",
- "star": "加星标"
+ "star": "加星标",
+ "selectMultipleHint": "多选(或在列表中按住 Ctrl / Shift 点击录音)"
},
"bulkReprocessModal": {
"fullTranscription": "完整转录",
diff --git a/templates/components/sidebar.html b/templates/components/sidebar.html
index c17b3294..f0dd8029 100644
--- a/templates/components/sidebar.html
+++ b/templates/components/sidebar.html
@@ -30,7 +30,7 @@
<button v-if="!selectionMode && recordings.length > 0"
@click="enterSelectionMode"
class="w-9 h-9 flex items-center justify-center bg-[var(--bg-accent)] text-[var(--text-accent)] rounded-md hover:opacity-80 transition-opacity"
- title="Select multiple">
+ :title="t('bulkActions.selectMultipleHint')">
<i class="fas fa-list-check"></i>
</button>
<button v-if="selectionMode"
@@ -416,7 +416,8 @@
<div class="recording-group">
<div v-for="recording in group.items"
:key="recording.id"
- @click="selectionMode ? toggleSelection(recording.id) : selectRecording(recording)"
+ @mousedown="$event.shiftKey && $event.preventDefault()"
+ @click="handleRecordingClick(recording, $event, visibleRecordingIds) || selectRecording(recording)"
:class="[
'recording-row relative px-3 py-2.5 cursor-pointer transition-colors',
selectionMode && isSelected(recording.id)
@@ -430,12 +431,12 @@
the title or change card heights when the
user toggles selection mode. -->
<div v-if="selectionMode"
- @click.stop="toggleSelection(recording.id)"
+ @click.stop="handleRecordingClick(recording, $event, visibleRecordingIds)"
class="absolute top-2 right-2 z-10">
<input type="checkbox"
:checked="isSelected(recording.id)"
class="selection-checkbox"
- @click.stop="toggleSelection(recording.id)">
+ @click.stop="handleRecordingClick(recording, $event, visibleRecordingIds)">
</div>
<!-- Title and Status Row -->
<div class="flex items-center justify-between mb-1"