Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit cc44fcc

Browse files
authored
fix: LSDV-5260: Selected region can not be moved / resized when it's under another region (#1454)
* fix: LSDV-5260: Selected region can not be moved / resized when it's under another region * adding test for region ordering * fix test
1 parent 92c4922 commit cc44fcc

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

e2e/tests/audio/audio-regions.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,49 @@ Scenario('Can select a region below a hidden region', async function({ I, LabelS
177177
AtSidebar.seeSelectedRegion('Speech');
178178
});
179179

180+
Scenario('Selecting a region brings it to the front of the stack', async function({ I, LabelStudio, AtAudioView, AtSidebar }) {
181+
LabelStudio.setFeatureFlags({
182+
ff_front_dev_2715_audio_3_280722_short: true,
183+
});
184+
I.amOnPage('/');
185+
186+
LabelStudio.init(paramsSpeech);
187+
188+
await AtAudioView.waitForAudio();
189+
await AtAudioView.lookForStage();
190+
191+
// create a new region
192+
I.pressKey('1');
193+
AtAudioView.dragAudioElement(50, 80);
194+
I.pressKey('u');
195+
196+
AtSidebar.seeRegions(1);
197+
198+
// create a new region above the first one
199+
I.pressKey('2');
200+
AtAudioView.dragAudioElement(49, 81);
201+
I.pressKey('u');
202+
203+
AtSidebar.seeRegions(2);
204+
205+
// click on the top-most region visible to select it
206+
AtAudioView.clickAt(50);
207+
AtSidebar.seeSelectedRegion('Noise');
208+
209+
// Select the bottom most region to bring it to the top
210+
AtSidebar.clickRegion('Speech');
211+
AtSidebar.seeSelectedRegion('Speech');
212+
213+
// click on the overlapping region will deselect it, which shows that it is now the top in the list
214+
AtAudioView.clickAt(50);
215+
AtSidebar.dontSeeSelectedRegion('Speech');
216+
AtSidebar.dontSeeSelectedRegion('Noise');
217+
218+
// click on the overlapping region will select the top item of the list, which will now be the item which was brought to the front by the original interaction.
219+
AtAudioView.clickAt(50);
220+
AtSidebar.seeSelectedRegion('Speech');
221+
});
222+
180223
Scenario('Delete region by pressing delete hotkey', async function({ I, LabelStudio, AtAudioView, AtSidebar }) {
181224
LabelStudio.setFeatureFlags({
182225
ff_front_dev_2715_audio_3_280722_short: true,

src/lib/AudioUltra/Regions/Regions.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { rgba, RgbaColorArray } from '../Common/Color';
2-
import { clamp, defaults, findLast, getCursorPositionX, getCursorPositionY, isInRange, pixelsToTime } from '../Common/Utils';
2+
import {
3+
clamp,
4+
defaults,
5+
findLast,
6+
getCursorPositionX,
7+
getCursorPositionY,
8+
isInRange,
9+
pixelsToTime
10+
} from '../Common/Utils';
311
import { CursorSymbol } from '../Cursor/Cursor';
412
import { LayerGroup } from '../Visual/LayerGroup';
513
import { Visualizer } from '../Visual/Visualizer';
@@ -187,6 +195,12 @@ export class Regions {
187195
}
188196
}
189197

198+
bringRegionToFront(regionId: string) {
199+
const originalIndex = this.regions.findIndex(reg => reg.id === regionId);
200+
201+
this.regions.push(...this.regions.splice(originalIndex, 1));
202+
}
203+
190204
destroy() {
191205
const { container } = this.visualizer;
192206

@@ -379,7 +393,6 @@ export class Regions {
379393
if (this.layerGroup.isVisible && region?.updateable) {
380394
e.preventDefault();
381395
e.stopPropagation();
382-
383396
region.invoke('mouseDown', [region, e]);
384397
}
385398
};
@@ -398,7 +411,7 @@ export class Regions {
398411

399412
if (e.target && mainLayer?.canvas?.contains(e.target)) {
400413
const region = this.findRegionUnderCursor(e);
401-
414+
402415
if (this.layerGroup.isVisible && region) {
403416
region.invoke('click', [region, e]);
404417
}

src/lib/AudioUltra/Regions/Segment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ export class Segment extends Events<SegmentEvents> {
130130
this.waveform.invoke('regionUpdated', [this]);
131131
}
132132

133+
/**
134+
* Move this segment to the front so it is readily available to the user to manipulate
135+
*/
136+
bringToFront() {
137+
this.controller.bringRegionToFront(this.id);
138+
}
139+
133140
protected get layerName() {
134141
return `region-${this.id}`;
135142
}
@@ -286,6 +293,7 @@ export class Segment extends Events<SegmentEvents> {
286293
const x = getCursorPositionX(e, container) + scrollLeft;
287294
const { start, end } = this;
288295

296+
this.bringToFront();
289297
this.draggingStartPosition = { grabPosition: x, start, end };
290298
this.isGrabbingEdge = this.edgeGrabCheck(e);
291299
document.addEventListener('mouseup', this.handleMouseUp);

src/regions/AudioRegion/AudioUltraRegionModel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const AudioUltraRegionModel = types
7777
selectRegion() {
7878
if (!self._ws_region) return;
7979
self._ws_region.handleSelected(true);
80+
self._ws_region.bringToFront();
8081
self._ws_region.scrollToRegion();
8182
},
8283

@@ -139,7 +140,7 @@ export const AudioUltraRegionModel = types
139140

140141
setProperty(propName, value) {
141142
Super.setProperty(propName, value);
142-
if ( ['start', 'end'].includes(propName) ) {
143+
if (['start', 'end'].includes(propName)) {
143144
self.updatePosition();
144145
}
145146
},

0 commit comments

Comments
 (0)