Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regions plugin: fix region ignoring minLength when being resized #2002

Merged
merged 5 commits into from
Jul 13, 2020
Merged

Conversation

sundayz
Copy link
Contributor

@sundayz sundayz commented Jul 10, 2020

Short description of changes:

  • Fix region onResize code not checking minLength, which allowed you to "push" regions while dragging them past the point where they should stop shrinking. See related issue for better description.
  • Fix handles CSS in region example. They were set to width: 1% which made them scale with the size of the region, and they became invisible when the region was small enough. Now they're always 2px.

Breaking in the external API:

None

Breaking changes in the internal API:

None

Todos/Notes:

The resizing behaviour in general could do with some improvements. For example I don't think you should be able to drag regions to size 0, because then you can't grab them again and you lose them. Maybe regions could have a default minLength: 0.1 or so.

Other possible future enhancements:

  • minLength is not documented in the example page.
  • minLength/maxLength don't seem to be used a lot in the code, maybe they were never fully implemented?
  • Resizing delta is calculated by checking difference between current and last mouse position. It would be better if you could only resize the region when your mouse was near the handle (maybe calculate delta as handle position change)
  • Other functions which affect region size should probably check minLength, not just onResize

Related Issues and other PRs:

fixes #2001
closes #2008

@coveralls
Copy link

coveralls commented Jul 10, 2020

Coverage Status

Coverage remained the same at 80.385% when pulling 653d8f6 on sundayz:master into b8cfabe on katspaugh:master.

@thijstriemstra thijstriemstra changed the title Fix region ignoring minLength when being resized regions plugin: fix region ignoring minLength when being resized Jul 11, 2020
Copy link
Contributor

@thijstriemstra thijstriemstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! can you also add a changelog entry?

example/regions/index.html Outdated Show resolved Hide resolved
this.update({
start: Math.min(this.start + delta, this.end),
end: Math.max(this.start + delta, this.end)
});
} else {
// Check if changing the end by the given delta would result in the region being smaller than minLength
// Ignore cases where we are making the region wider rather than shrinking it
if (delta < 0 && Math.abs((this.end + delta) - this.start) < this.minLength) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about Math.abs. Also curious why we have to check for delta > 0 and delta < 0; the checks are sorta fine, but was there a specific reason to put them in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since minLength isn't checked everywhere, it's actually possible to manually call this.update() and set the region to a size smaller than minLength. The delta check makes sure that if the area is too small, you can still make it bigger, but not shrink it further when dragging it with the mouse. A better fix would be to make sure the region can never be smaller than minLength, but I'm not familiar enough with this plugin to make that change.

@marizuccara
Copy link
Contributor

Hi great idea and very useful! It would be even better if the minLength property was not related only to a single region which you define on initialization, but also when you create a region "manually", directly on the waveform. Because actually, for the regions you create with dragging, the problem persists. Maybe it would be better to define a general minLength prop, valid for all regions, even for the new ones that will be created in the future.

@marizuccara
Copy link
Contributor

Hi great idea and very useful! It would be even better if the minLength property was not related only to a single region which you define on initialization, but also when you create a region "manually", directly on the waveform. Because actually, for the regions you create with dragging, the problem persists. Maybe it would be better to define a general minLength prop, valid for all regions, even for the new ones that will be created in the future.

Hi, @sundayz, are you planning to open a PR for this, or can I proceed?

@sundayz
Copy link
Contributor Author

sundayz commented Jul 19, 2020

@marizuccara You can do it if you'd like :) I will try to fix #2006 soon, should we do 1 PR to fix multiple issues with regions, or do a separate PR for each issue? #1925 also added something to regions in 4.0 which should be changed to a configuration option since it stops the seeker from working within regions

@thijstriemstra
Copy link
Contributor

should we do 1 PR to fix multiple issues with regions, or do a separate PR for each issue?

One per issue, it makes it easier to track changes later on. I was thinking of doing a 4.1.0 release next week, but it can wait till regions plugin improvements you talk about are merged.

sandiz pushed a commit to sandiz/wavesurfer.js that referenced this pull request Sep 1, 2021
…spaugh#2002)

* fix region not respecting minLength when being resized

* fix region handle CSS in example being hard to grab when the region is small

* Change region handle default width to 2px rather than 1% of the region width

* Remove redundant math.abs check

* add changelog entry (katspaugh#2002)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants