shortcut to select all

This commit is contained in:
vcoppe
2024-04-22 11:45:57 +02:00
parent 515ad7048d
commit 02f2ace72e
3 changed files with 24 additions and 4 deletions

View File

@@ -2,12 +2,13 @@
import { fileOrder, files, selectedFiles, selectFiles } from '$lib/stores';
import { ScrollArea } from '$lib/components/ui/scroll-area/index';
import Sortable from 'sortablejs/Sortable';
import { onMount, tick } from 'svelte';
import type { GPXFile } from 'gpx';
import { onMount } from 'svelte';
import { get } from 'svelte/store';
let tabs: HTMLDivElement;
let buttons: HTMLButtonElement[] = [];
let sortable: Sortable;
@@ -27,6 +28,15 @@
});
}
function selectAllFiles() {
selectedFiles.update((selectedFiles) => {
get(files).forEach((file) => {
selectedFiles.add(file);
});
return selectedFiles;
});
}
function deselectFile(file: GPXFile) {
selectedFiles.update((selectedFiles) => {
selectedFiles.delete(file);
@@ -81,6 +91,12 @@
Sortable.utils.select(buttons[index]);
addSelectFile(file);
},
selectAllFiles: () => {
$files.forEach((file, index) => {
Sortable.utils.select(buttons[index]);
});
selectAllFiles();
},
removeSelect: (file: GPXFile) => {
const index = $files.indexOf(file);
Sortable.utils.deselect(buttons[index]);

View File

@@ -22,7 +22,8 @@
exportSelectedFiles,
removeAllFiles,
removeSelectedFiles,
triggerFileInput
triggerFileInput,
selectFiles
} from '$lib/stores';
let distanceUnits = 'metric';
@@ -170,6 +171,9 @@
removeSelectedFiles();
}
e.preventDefault();
} else if (e.key === 'a' && (e.metaKey || e.ctrlKey)) {
$selectFiles.selectAllFiles();
e.preventDefault();
}
}}
/>

View File

@@ -7,7 +7,7 @@ export const map = writable<mapboxgl.Map | null>(null);
export const files = writable<GPXFile[]>([]);
export const fileOrder = writable<GPXFile[]>([]);
export const selectedFiles = writable<Set<GPXFile>>(new Set());
export const selectFiles = writable<{ [key: string]: (file: GPXFile) => void }>({});
export const selectFiles = writable<{ [key: string]: (file?: GPXFile) => void }>({});
export function triggerFileInput() {
const input = document.createElement('input');