mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
fix selection reset after updates
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { GPXFile, Track, Waypoint, type AnyGPXTreeElement, type GPXTreeElement } from 'gpx';
|
||||
import { afterUpdate, getContext, onMount } from 'svelte';
|
||||
import { afterUpdate, getContext, onDestroy, onMount } from 'svelte';
|
||||
import Sortable from 'sortablejs/Sortable';
|
||||
import { getFileIds, settings, type GPXFileWithStatistics } from '$lib/db';
|
||||
import { get, writable, type Readable, type Writable } from 'svelte/store';
|
||||
@@ -48,8 +48,13 @@
|
||||
let sortable: Sortable;
|
||||
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
||||
|
||||
let destroyed = false;
|
||||
let lastUpdateStart = 0;
|
||||
function updateToSelection(e) {
|
||||
if (destroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastUpdateStart = Date.now();
|
||||
setTimeout(() => {
|
||||
if (Date.now() - lastUpdateStart >= 40) {
|
||||
@@ -89,7 +94,9 @@
|
||||
}
|
||||
|
||||
function updateFromSelection() {
|
||||
if (updating) return;
|
||||
if (destroyed || updating) {
|
||||
return;
|
||||
}
|
||||
updating = true;
|
||||
// Selection updates sortable
|
||||
let changed = getChangedIds();
|
||||
@@ -229,6 +236,7 @@
|
||||
|
||||
onMount(() => {
|
||||
createSortable();
|
||||
destroyed = false;
|
||||
});
|
||||
|
||||
afterUpdate(() => {
|
||||
@@ -250,6 +258,10 @@
|
||||
updateFromSelection();
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
destroyed = true;
|
||||
});
|
||||
|
||||
function getChangedIds() {
|
||||
let changed: (string | number)[] = [];
|
||||
Object.entries(elements).forEach(([id, element]) => {
|
||||
|
Reference in New Issue
Block a user