Changeset 35649
- Timestamp:
- 2021-10-20T15:23:18+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/WordTimingSelector.vue
r35648 r35649 303 303 }, 304 304 305 /** 306 * Handles the document.onmousemove event. 307 * @param {MouseEvent} event The mouse event. 308 */ 305 309 onDocumentMouseMove(event) { 306 if (this.canAdjustWordStartTime) {307 this.onMinHandleMouseMove(event);308 }309 else if (this.canAdjustWordEndTime) {310 this.onMaxHandleMouseMove(event);311 }312 },313 /**314 * @param {MouseEvent} event315 */316 onMinHandleMouseMove(event) {317 310 if (event.buttons < 1) { 318 311 return; 319 312 } 320 313 321 this.adjustWordStartTime(event.movementX); 322 323 this.emitWordUpdates(this.mySurroundingWords); 324 }, 325 onMaxHandleMouseMove(event) { 326 if (event.buttons < 1) { 327 return; 328 } 329 330 this.adjustWordEndTime(event.movementX); 314 if (this.canAdjustWordStartTime) { 315 this.adjustWordStartTime(event.movementX); 316 } 317 else if (this.canAdjustWordEndTime) { 318 this.adjustWordEndTime(event.movementX); 319 } 331 320 332 321 this.emitWordUpdates(this.mySurroundingWords); … … 338 327 339 328 adjustWordStartTime(amount) { 329 /** @type {Word} */ 340 330 const word = this.myWord; 331 /** @type {Word} */ 332 const previousWord = this.wordIndex === 0 333 ? null 334 : this.mySurroundingWords[this.wordIndex - 1]; 335 341 336 word.left += amount; 342 337 word.length -= amount; 343 338 344 339 if (amount < 0) { 340 // Prevent the first word from being expanded to a time less than zero. 345 341 if (this.wordIndex === 0) { 346 342 if (word.left > 0) { … … 353 349 } 354 350 else { 355 // Adjust previous word 356 const previousWord = this.mySurroundingWords[this.wordIndex - 1]; 357 351 // Check if we've encroached on the previous word 358 352 if (word.left > previousWord.right()) { 359 353 return; … … 361 355 362 356 previousWord.length += amount; 357 358 // Ensure the previous word is at least 0.1s in length 363 359 const leftBoundary = previousWord.left + this.scaleTime(0.1); 364 365 360 if (previousWord.right() > leftBoundary) { 366 361 return; … … 374 369 } 375 370 else { 371 // Prevent the word from being shrunk beyond 0.1s length 376 372 const rightBoundary = word.right() - this.scaleTime(0.1); 377 373 if (word.left > rightBoundary) { … … 380 376 word.length += diff; 381 377 } 378 379 // If we were touching the previous word, drag it up till it reaches it's original length 380 if (previousWord !== null && word.left - amount - 1 <= previousWord.right()) { 381 previousWord.length += amount; 382 383 const shadow = this.shadowWords[this.wordIndex - 1]; 384 if (previousWord.right() > shadow.right()) { 385 const diff = previousWord.right() - shadow.right(); 386 previousWord.length -= diff; 387 } 388 } 382 389 } 383 390 }, 384 391 adjustWordEndTime(amount) { 392 /** @type {Word} */ 385 393 const word = this.myWord; 394 /** @type {Word} */ 395 const nextWord = this.wordIndex === this.mySurroundingWords.length - 1 396 ? null 397 : this.mySurroundingWords[this.wordIndex + 1]; 398 386 399 word.length += amount; 387 400 388 401 if (amount > 0) { 402 // Prevent the last word from being expanded beyond the length of the audio. 389 403 if (this.wordIndex === this.mySurroundingWords.length - 1) { 390 404 const rightBoundary = this.scaleTime(this.audioSnippetLength); … … 398 412 } 399 413 else { 400 const nextWord = this.mySurroundingWords[this.wordIndex + 1]; 401 414 // Check if we've encroached on the next word 402 415 if (word.right() < nextWord.left) { 403 416 return; … … 407 420 nextWord.length -= amount; 408 421 422 // Ensure that the next word is at least 0.1s in length 409 423 const rightBoundary = nextWord.right() - this.scaleTime(0.1); 410 411 424 if (nextWord.left < rightBoundary) { 412 425 return; … … 420 433 } 421 434 else { 435 // Prevent the word from being shrunk beyond 0.1s length 422 436 const leftBoundary = word.left + this.scaleTime(0.1); 423 437 if (word.right() < leftBoundary) { 424 438 const diff = leftBoundary - word.right(); 425 439 word.length += diff; 440 } 441 442 // If we were touching the next word, drag it back till it reaches it's original length 443 if (nextWord !== null && word.right() - amount + 1 >= nextWord.left) { 444 nextWord.left += amount; 445 nextWord.length -= amount; 446 447 const shadow = this.shadowWords[this.wordIndex + 1]; 448 if (nextWord.left < shadow.left) { 449 const diff = shadow.left - nextWord.left; 450 nextWord.length -= diff; 451 nextWord.left += diff; 452 } 426 453 } 427 454 }
Note:
See TracChangeset
for help on using the changeset viewer.