This commit is contained in:
vcoppe committed 2026-10-07 18:54:00 +02:00
1 parent 290f4d8c44
commit e07ec97e12
5 files changed
+339 -39

No files matched your search

@@ -15,8 +15,8 @@
import { SplitControls } from './split-controls';
import { getURLForLanguage } from '$lib/utils';
import { selection } from '$lib/logic/selection';
import { fileActions } from '$lib/logic/file-actions';
import { gpxStatistics, slicedGPXStatistics } from '$lib/logic/statistics';
import { engine } from '$lib/engine';
let props: {
class?: string;
@@ -95,7 +95,7 @@
<Button
variant="outline"
disabled={!validSelection || !canCrop}
onclick={() => fileActions.cropSelection(sliderValues[0], sliderValues[1])}
onclick={() => engine.crop(sliderValues[0], sliderValues[1])}
>
<Crop size="16" />{i18n._('toolbar.scissors.crop')}
</Button>
+10
View File
@@ -645,6 +645,16 @@ class Engine {
return this.run((w) => w.reverse());
}
/**
* Keeps the trackpoints `start` to `end` (both included) of the selection, counted over its
* segments one after the other, and removes the others, with the segments, tracks and files
* that are left empty (tracks and files only if they are selected). Resolves to `false` when
* the range covers the whole selection.
*/
crop(start: number, end: number) {
return this.run((w) => w.crop(Math.max(start, 0), Math.max(end, 0)));
}
/**
* Makes each selected segment (or the segments of the selected files and tracks) come back to
* where it started: a reversed copy of it is added after its last trackpoint (which is not
-33
View File
@@ -249,39 +249,6 @@ export const fileActions = {
}
});
},
cropSelection: (start: number, end: number) => {
if (get(selection).size === 0) {
return;
}
fileActionManager.applyGlobal((draft) => {
selection.applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
let file = draft.get(fileId);
if (file) {
if (level === ListLevel.FILE) {
let length = file.getNumberOfTrackPoints();
if (start >= length || end < 0) {
draft.delete(fileId);
} else if (start > 0 || end < length - 1) {
file.crop(Math.max(0, start), Math.min(length - 1, end));
}
start -= length;
end -= length;
} else if (level === ListLevel.TRACK) {
let trackIndices = items.map((item) =>
(item as ListTrackItem).getTrackIndex()
);
file.crop(start, end, trackIndices);
} else if (level === ListLevel.SEGMENT) {
let trackIndices = [(items[0] as ListTrackSegmentItem).getTrackIndex()];
let segmentIndices = items.map((item) =>
(item as ListTrackSegmentItem).getSegmentIndex()
);
file.crop(start, end, trackIndices, segmentIndices);
}
}
}, false);
});
},
extractSelection: () => {
return fileActionManager.applyGlobal((draft) => {
selection.applyToOrderedSelectedItemsFromFile((fileId, level, items) => {