Skip to content

Commit 587d8c3

Browse files
committed
Fix marker handle activation when dragging the playhead
This change disables interaction with the points and segments layers when the user drags the playhead, e.g., so that when dragging over a marker, the timestamp labels don't appear.
1 parent 0a60aa1 commit 587d8c3

6 files changed

+57
-3
lines changed

src/points-layer.js

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ PointsLayer.prototype.addToStage = function(stage) {
6363
stage.add(this._layer);
6464
};
6565

66+
PointsLayer.prototype.setListening = function(listening) {
67+
this._layer.listening(listening);
68+
};
69+
6670
PointsLayer.prototype.enableEditing = function(enable) {
6771
this._enableEditing = enable;
6872
};

src/scroll-mouse-drag-handler.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import { clamp } from './utils';
2323
function ScrollMouseDragHandler(peaks, view) {
2424
this._peaks = peaks;
2525
this._view = view;
26+
this._seeking = false;
27+
this._firstMove = false;
28+
this._segment = null;
29+
this._segmentIsDraggable = false;
30+
this._initialFrameOffset = 0;
31+
this._mouseDownX = 0;
2632

2733
this._onMouseDown = this._onMouseDown.bind(this);
2834
this._onMouseMove = this._onMouseMove.bind(this);
@@ -41,6 +47,7 @@ ScrollMouseDragHandler.prototype.isDragging = function() {
4147

4248
ScrollMouseDragHandler.prototype._onMouseDown = function(mousePosX, segment) {
4349
this._seeking = false;
50+
this._firstMove = true;
4451

4552
if (segment && !segment.attrs.draggable) {
4653
this._segment = null;
@@ -85,6 +92,11 @@ ScrollMouseDragHandler.prototype._onMouseMove = function(mousePosX) {
8592
}
8693

8794
if (this._seeking) {
95+
if (this._firstMove) {
96+
this._view.dragSeek(true);
97+
this._firstMove = false;
98+
}
99+
88100
mousePosX = clamp(mousePosX, 0, this._view.getWidth());
89101

90102
const time = this._view.pixelsToTime(mousePosX + this._view.getFrameOffset());
@@ -108,7 +120,10 @@ ScrollMouseDragHandler.prototype._onMouseMove = function(mousePosX) {
108120
};
109121

110122
ScrollMouseDragHandler.prototype._onMouseUp = function() {
111-
if (!this._seeking) {
123+
if (this._seeking) {
124+
this._view.dragSeek(false);
125+
}
126+
else {
112127
// Set playhead position only on click release, when not dragging.
113128
if (this._view._enableSeek && !this._mouseDragHandler.isDragging()) {
114129
const time = this._view.pixelOffsetToTime(this._mouseDownX);

src/seek-mouse-drag-handler.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,37 @@ import { clamp } from './utils';
2323
function SeekMouseDragHandler(peaks, view) {
2424
this._peaks = peaks;
2525
this._view = view;
26+
this._firstMove = false;
2627

2728
this._onMouseDown = this._onMouseDown.bind(this);
2829
this._onMouseMove = this._onMouseMove.bind(this);
30+
this._onMouseUp = this._onMouseUp.bind(this);
2931

3032
this._mouseDragHandler = new MouseDragHandler(view._stage, {
3133
onMouseDown: this._onMouseDown,
32-
onMouseMove: this._onMouseMove
34+
onMouseMove: this._onMouseMove,
35+
onMouseUp: this._onMouseUp
3336
});
3437
}
3538

3639
SeekMouseDragHandler.prototype._onMouseDown = function(mousePosX) {
40+
this._firstMove = true;
3741
this._seek(mousePosX);
3842
};
3943

4044
SeekMouseDragHandler.prototype._onMouseMove = function(mousePosX) {
45+
if (this._firstMove) {
46+
this._view.dragSeek(true);
47+
this._firstMove = false;
48+
}
49+
4150
this._seek(mousePosX);
4251
};
4352

53+
SeekMouseDragHandler.prototype._onMouseUp = function(mousePosX) {
54+
this._view.dragSeek(false);
55+
};
56+
4457
SeekMouseDragHandler.prototype._seek = function(mousePosX) {
4558
if (!this._view.isSeekEnabled()) {
4659
return;

src/segments-layer.js

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ SegmentsLayer.prototype.addToStage = function(stage) {
5252
stage.add(this._layer);
5353
};
5454

55+
SegmentsLayer.prototype.setListening = function(listening) {
56+
this._layer.listening(listening);
57+
};
58+
5559
SegmentsLayer.prototype.enableEditing = function(enable) {
5660
this._enableEditing = enable;
5761
};

src/waveform-view.js

+17
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,23 @@ WaveformView.prototype.enableMarkerEditing = function(enable) {
430430
}
431431
};
432432

433+
/**
434+
* Called when the user starts or stops dragging the playhead.
435+
* We use this to disable interaction with the points and segments layers,
436+
* e.g., so that when the user drags the playhead over a marker, the timestamp
437+
* labels don't appear.
438+
*/
439+
440+
WaveformView.prototype.dragSeek = function(dragging) {
441+
if (this._segmentsLayer) {
442+
this._segmentsLayer.setListening(!dragging);
443+
}
444+
445+
if (this._pointsLayer) {
446+
this._pointsLayer.setListening(!dragging);
447+
}
448+
};
449+
433450
WaveformView.prototype.fitToContainer = function() {
434451
if (this._container.clientWidth === 0 && this._container.clientHeight === 0) {
435452
return;

src/waveform-zoomview.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ WaveformZoomView.prototype._onWheelCaptureVerticalScroll = function(event) {
176176
};
177177

178178
WaveformZoomView.prototype.setWaveformDragMode = function(mode) {
179-
if (this._viewOptions.enableSegments) {
179+
if (this._segmentsLayer) {
180180
this._mouseDragHandler.destroy();
181+
this._dragSeek(false);
181182

182183
if (mode === 'insert-segment') {
183184
this._mouseDragHandler = new InsertSegmentMouseDragHandler(this._peaks, this);

0 commit comments

Comments
 (0)