Skip to content

Commit 5a772c8

Browse files
authored
regions plugin: improved delta calculation (resize end) (#2641)
* Improved delta calculation (resize end) With the use case that I use this library for, users need to be able to resize the regions. When a region was resized and afterward set back to the min length (f.e. 3.1 sec or in HMSM, which is how we show it, 00:00:03:10) it would stay at 3.12sec (00:00:03:12) or 3.14sec (00:00:03:14) or something, but never go back down all the way to 3.1 (00:00:03:10). With these changes, the length of the region can be set back to 3.10 exactly * Update: code feedback implemented * Add: changelog entry
1 parent 8bcb3b8 commit 5a772c8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
wavesurfer.js changelog
22
=======================
33

4+
6.5.0 (unreleased)
5+
------------------
6+
- Regions plugin:
7+
- Improved delta calculation (resize end) (#2641)
8+
49
6.4.0 (05.11.2022)
510
------------------
611
- Markers plugin:

src/plugin/regions/region.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ export class Region {
586586
const onMove = (event) => {
587587
const duration = this.wavesurfer.getDuration();
588588
let orientedEvent = this.util.withOrientation(event, this.vertical);
589+
let delta = null;
589590

590591
if (event.touches && event.touches.length > 1) {
591592
return;
@@ -632,7 +633,9 @@ export class Region {
632633
}
633634
} else if (resize === 'end') {
634635
if (time < this.start + minLength) {
636+
// Calculate the end time based on the min length of the region.
635637
time = this.start + minLength;
638+
delta = time - (this.end + (time - startTime));
636639
}
637640

638641
if (time > duration) {
@@ -641,7 +644,10 @@ export class Region {
641644
}
642645
}
643646

644-
let delta = time - startTime;
647+
if (!delta) {
648+
delta = time - startTime;
649+
}
650+
645651
startTime = time;
646652

647653
// Drag

0 commit comments

Comments
 (0)