Changeset 35649


Ignore:
Timestamp:
2021-10-20T15:23:18+13:00 (3 years ago)
Author:
cstephen
Message:

Snap words back to shadow on collision edit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/WordTimingSelector.vue

    r35648 r35649  
    303303        },
    304304
     305        /**
     306         * Handles the document.onmousemove event.
     307         * @param {MouseEvent} event The mouse event.
     308         */
    305309        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} event
    315          */
    316         onMinHandleMouseMove(event) {
    317310            if (event.buttons < 1) {
    318311                return;
    319312            }
    320313
    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            }
    331320
    332321            this.emitWordUpdates(this.mySurroundingWords);
     
    338327
    339328        adjustWordStartTime(amount) {
     329            /** @type {Word} */
    340330            const word = this.myWord;
     331            /** @type {Word} */
     332            const previousWord = this.wordIndex === 0
     333                ? null
     334                : this.mySurroundingWords[this.wordIndex - 1];
     335
    341336            word.left += amount;
    342337            word.length -= amount;
    343338
    344339            if (amount < 0) {
     340                // Prevent the first word from being expanded to a time less than zero.
    345341                if (this.wordIndex === 0) {
    346342                    if (word.left > 0) {
     
    353349                }
    354350                else {
    355                     // Adjust previous word
    356                     const previousWord = this.mySurroundingWords[this.wordIndex - 1];
    357 
     351                    // Check if we've encroached on the previous word
    358352                    if (word.left > previousWord.right()) {
    359353                        return;
     
    361355
    362356                    previousWord.length += amount;
     357
     358                    // Ensure the previous word is at least 0.1s in length
    363359                    const leftBoundary = previousWord.left + this.scaleTime(0.1);
    364 
    365360                    if (previousWord.right() > leftBoundary) {
    366361                        return;
     
    374369            }
    375370            else {
     371                // Prevent the word from being shrunk beyond 0.1s length
    376372                const rightBoundary = word.right() - this.scaleTime(0.1);
    377373                if (word.left > rightBoundary) {
     
    380376                    word.length += diff;
    381377                }
     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                }
    382389            }
    383390        },
    384391        adjustWordEndTime(amount) {
     392            /** @type {Word} */
    385393            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
    386399            word.length += amount;
    387400
    388401            if (amount > 0) {
     402                // Prevent the last word from being expanded beyond the length of the audio.
    389403                if (this.wordIndex === this.mySurroundingWords.length - 1) {
    390404                    const rightBoundary = this.scaleTime(this.audioSnippetLength);
     
    398412                }
    399413                else {
    400                     const nextWord = this.mySurroundingWords[this.wordIndex + 1];
    401 
     414                    // Check if we've encroached on the next word
    402415                    if (word.right() < nextWord.left) {
    403416                        return;
     
    407420                    nextWord.length -= amount;
    408421
     422                    // Ensure that the next word is at least 0.1s in length
    409423                    const rightBoundary = nextWord.right() - this.scaleTime(0.1);
    410 
    411424                    if (nextWord.left < rightBoundary) {
    412425                        return;
     
    420433            }
    421434            else {
     435                // Prevent the word from being shrunk beyond 0.1s length
    422436                const leftBoundary = word.left + this.scaleTime(0.1);
    423437                if (word.right() < leftBoundary) {
    424438                    const diff = leftBoundary - word.right();
    425439                    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                    }
    426453                }
    427454            }
Note: See TracChangeset for help on using the changeset viewer.