Skip to content

Commit

Permalink
Prevent inserting segments in 'no-overlap' or 'compress' mode
Browse files Browse the repository at this point in the history
This change prevents inserting new segments if the user
clicks on an existing segment, where the segment drag mode
is 'no-overlap' or 'compress'.

See #524
  • Loading branch information
chrisn committed Feb 19, 2024
1 parent 3a4485c commit 527e857
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 163 deletions.
21 changes: 15 additions & 6 deletions src/insert-segment-mouse-drag-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ InsertSegmentMouseDragHandler.prototype._onMouseDown = function(mousePosX, segme
this._segment = segment;

if (this._segment) {
// The user has clicked within a segment. We want to prevent
// the segment from being dragged while the user inserts a new
// segment. So we temporarily make the segment non-draggable,
// and restore its draggable state in onMouseUp().
this._segmentIsDraggable = this._segment.draggable();
this._segment.draggable(false);
if (this._view.getSegmentDragMode() !== 'overlap') {
return;
}
else {
// The user has clicked within a segment. We want to prevent
// the segment from being dragged while the user inserts a new
// segment. So we temporarily make the segment non-draggable,
// and restore its draggable state in onMouseUp().
this._segmentIsDraggable = this._segment.draggable();
this._segment.draggable(false);
}
}

const time = this._view.pixelsToTime(mousePosX + this._view.getFrameOffset());
Expand All @@ -72,6 +77,10 @@ InsertSegmentMouseDragHandler.prototype._onMouseMove = function() {
};

InsertSegmentMouseDragHandler.prototype._onMouseUp = function() {
if (!this._insertSegment) {
return;
}

if (this._insertSegmentShape) {
this._insertSegmentShape.stopDrag();
this._insertSegmentShape = null;
Expand Down
2 changes: 1 addition & 1 deletion src/mouse-drag-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ MouseDragHandler.prototype._mouseDown = function(event) {

const marker = getMarkerObject(event.target);

if (marker && marker.attrs.draggable) {
if (marker) {
// Avoid interfering with drag/drop of point and segment markers.
if (marker.attrs.name === 'point-marker' ||
marker.attrs.name === 'segment-marker') {
Expand Down
8 changes: 7 additions & 1 deletion src/scroll-mouse-drag-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ ScrollMouseDragHandler.prototype.isDragging = function() {
};

ScrollMouseDragHandler.prototype._onMouseDown = function(mousePosX, segment) {
this._segment = segment;
this._seeking = false;

if (segment && !segment.attrs.draggable) {
this._segment = null;
}
else {
this._segment = segment;
}

const playheadOffset = this._view.getPlayheadOffset();

if (this._view.isSeekEnabled() &&
Expand Down
Loading

0 comments on commit 527e857

Please sign in to comment.