Changeset 35537


Ignore:
Timestamp:
2021-10-01T10:51:07+13:00 (3 years ago)
Author:
cstephen
Message:

Join words when deleting on either edge

File:
1 edited

Legend:

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

    r35528 r35537  
    186186            log(event);
    187187
     188            // https://rawgit.com/w3c/input-events/v1/index.html#interface-InputEvent-Attributes
    188189            const deletionEvents = [
    189190                "deleteWordForward", "deleteWordBackward",
     
    214215                if (word.word.length === 0) { // Remove the word
    215216                    this.setFocus(index, event.inputType === "deleteContentBackward"); // Shifting focus off an empty input, hence the word will be removed
    216                     event.preventDefault(); // Prevents the event from being propagated to the newly focused input
    217217                    // TODO: Shuffle timestamps
    218                 }
    219                 else if (inputIndex === 0 && event.inputType === "deleteContentBackward") {
    220                     // TODO: Join with previous
    221                 }
    222                 else if (inputIndex === word.word.length && event.inputType === "deleteContentForward") {
    223                     // TODO: Join with next
     218
     219                    event.preventDefault();
     220                }
     221                else if (inputIndex === 0 && event.inputType === "deleteContentBackward") { // Join with last word
     222                    if (index === 0) {
     223                        return;
     224                    }
     225                    else if (this.words.length > 1) {
     226                        this.words[index - 1].endTime = word.endTime;
     227                        this.words[index - 1].word += word.word;
     228
     229                        word.word = "";
     230                        this.setFocus(index, true);
     231                    }
     232
     233                    event.preventDefault();
     234                }
     235                else if (inputIndex === word.word.length && event.inputType === "deleteContentForward") { // Join with next word
     236                    if (index === this.words.length - 1) {
     237                        return;
     238                    }
     239                    else if (this.words.length > 1) {
     240                        this.words[index + 1].startTime = word.startTime;
     241                        this.words[index + 1].word = word.word + this.words[index + 1].word;
     242
     243                        word.word = "";
     244                        this.setFocus(index, false);
     245                    }
     246
     247                    event.preventDefault();
    224248                }
    225249            }
     
    253277                    }
    254278
     279                    // Prevent the event from being propagated to the newly focused input
    255280                    event.preventDefault();
     281
    256282                    // Give the element time to be mounted before focusing
    257283                    setTimeout(
Note: See TracChangeset for help on using the changeset viewer.