Skip to content

Commit

Permalink
regions plugin: improved delta calculation (resize end) (katspaugh#2641)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BQTH committed Jan 26, 2023
1 parent 8bcb3b8 commit 5a772c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
wavesurfer.js changelog
=======================

6.5.0 (unreleased)
------------------
- Regions plugin:
- Improved delta calculation (resize end) (#2641)

6.4.0 (05.11.2022)
------------------
- Markers plugin:
Expand Down
8 changes: 7 additions & 1 deletion src/plugin/regions/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ export class Region {
const onMove = (event) => {
const duration = this.wavesurfer.getDuration();
let orientedEvent = this.util.withOrientation(event, this.vertical);
let delta = null;

if (event.touches && event.touches.length > 1) {
return;
Expand Down Expand Up @@ -632,7 +633,9 @@ export class Region {
}
} else if (resize === 'end') {
if (time < this.start + minLength) {
// Calculate the end time based on the min length of the region.
time = this.start + minLength;
delta = time - (this.end + (time - startTime));
}

if (time > duration) {
Expand All @@ -641,7 +644,10 @@ export class Region {
}
}

let delta = time - startTime;
if (!delta) {
delta = time - startTime;
}

startTime = time;

// Drag
Expand Down

0 comments on commit 5a772c8

Please sign in to comment.