Skip to content

Commit

Permalink
Feat: [Regions] pass sensitivity threshold to enableDragSelection (#3437
Browse files Browse the repository at this point in the history
)
  • Loading branch information
katspaugh authored Dec 23, 2023
1 parent a00e6db commit a1f9302
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export function makeDraggable(
const y = event.clientY
const dx = x - startX
const dy = y - startY
startX = x
startY = y

if (isDragging || Math.abs(dx) > threshold || Math.abs(dy) > threshold) {
const rect = element.getBoundingClientRect()
Expand All @@ -41,6 +39,9 @@ export function makeDraggable(
}

onDrag(dx, dy, x - left, y - top)

startX = x
startY = y
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ class RegionsPlugin extends BasePlugin<RegionsPluginEvents, RegionsPluginOptions
* Enable creation of regions by dragging on an empty space on the waveform.
* Returns a function to disable the drag selection.
*/
public enableDragSelection(options: Omit<RegionParams, 'start' | 'end'>): () => void {
public enableDragSelection(options: Omit<RegionParams, 'start' | 'end'>, threshold = 3): () => void {
const wrapper = this.wavesurfer?.getWrapper()
if (!wrapper || !(wrapper instanceof HTMLElement)) return () => undefined

Expand Down Expand Up @@ -588,6 +588,8 @@ class RegionsPlugin extends BasePlugin<RegionsPluginEvents, RegionsPluginOptions
region = null
}
},

threshold,
)
}

Expand Down

0 comments on commit a1f9302

Please sign in to comment.