Changeset 35516
- Timestamp:
- 2021-09-29T13:37:53+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItemEditor.vue
r35510 r35516 12 12 <ul class="list-view" v-else> 13 13 <li v-for="(word, index) in words" :key="word.id" class="word-container"> 14 <input :size="word.word.length " :ref="word.id"14 <input :size="word.word.length === 0 ? 1 : word.word.length" :ref="word.id" 15 15 class="editor-word" v-model="word.word" type="text" onpaste="return false;" :class="{ 'word-highlight-applied': word.shouldHighlight }" 16 @ input="onEditorInput($event, index)" @focusout="onEditorFocusOut(index)" @keyup="onEditorKeyUp($event, index)" @focus="onEditorFocus(index)" />16 @beforeinput="onEditorBeforeInput($event, index)" @focusout="onEditorFocusOut(index)" @keyup="onEditorKeyUp($event, index)" @focus="onEditorFocus(index)" /> 17 17 <span> </span> 18 18 </li> … … 88 88 import AudioTimeBar from "./AudioTimeBar.vue" 89 89 import WordTimingSelector from "./WordTimingSelector.vue" 90 import Util from "../js/Util";90 import Util, { log } from "../js/Util"; 91 91 92 92 export class Word { … … 179 179 /** 180 180 * Invoked when the value of a word changes. 181 * @param event The input event.181 * @param {InputEvent} event The input event. 182 182 * @param {Number} index The index of the word that has changed. 183 183 */ 184 onEditorInput(event, index) { 184 onEditorBeforeInput(event, index) { 185 log(event); 186 187 const deletionEvents = [ 188 "deleteWordForward", "deleteWordBackward", 189 "deleteSoftLineBackward", "deleteSoftLineForward", "deleteEntireSoftLine", 190 "deleteHardLineBackward", "deleteHardLineForward", 191 "deleteByDrag", "deleteByCut", 192 "deleteContent", "deleteContentBackward", "deleteContentForward" 193 ]; 194 195 const insertionEvents = [ 196 "insertText", "insertReplacementText", 197 "insertLineBreak", "insertParagraph", 198 "insertOrderedList", "insertUnorderedList", "insertHorizontalRule", 199 "insertFromYank", "insertFromDrop", "insertFromPaste", "insertFromPasteAsQuotation", 200 "insertTranspose", "insertCompositionText", "insertLink" 201 ]; 202 203 if (event.inputType === "historyUndo" || event.inputType === "historyRedo") { 204 event.preventDefault(); 205 return; 206 } 207 185 208 /** @type {Word} */ 186 209 const word = this.words[index]; 187 210 188 if (event.inputType === "insertText") { 189 // Insert a new word if whitespace is entered on an existing word 190 if (event.data === " " && word.word !== " ") { 191 const newStartTime = word.startTime + ((word.endTime - word.startTime) / 2); 192 const newWord = new Word("", newStartTime, word.endTime); 193 this.words.splice(index + 1, 0, newWord); 194 195 // We have to give the element some time to render, even though the ref is registered immediately 196 setTimeout(() => this.$refs[newWord.id].focus(), 50); 211 if (deletionEvents.includes(event.inputType) && word.word.length === 0) { 212 event.preventDefault(); // Prevents the event from being propagated to the newly focused input 213 this.setFocus(index, event.inputType === "deleteContentBackward"); // Shifting focus off an empty input, hence the word will be removed 214 } 215 216 if (insertionEvents.includes(event.inputType)) { 217 if (event.data === " ") { 218 // Only insert if the current word isn't blank, to prevent 'jumping jacks' as the duplicate empty boxes are removed 219 if (word.word !== "") { 220 const newStartTime = word.startTime + ((word.endTime - word.startTime) / 2); 221 const newWord = new Word("", newStartTime, word.endTime); 222 this.words.splice(index + 1, 0, newWord); 223 224 // We have to give the element some time to be mounted before we can focus it 225 setTimeout(() => this.$refs[newWord.id].focus(), 50); 226 } 227 228 event.preventDefault(); 197 229 } 198 199 word.word = word.word.replace(" ", "");200 230 } 201 231 }, … … 218 248 const word = this.words[index]; 219 249 220 // Remove the word if the user is repetitively hitting backspace/delete on an empty cell 221 if (event.code === "Backspace" || event.code === "Delete") { 222 if (word.word.length < 1) { 223 if (word.deletionAttempts === 1) { 224 this.words.splice(index, 1); 225 226 this.setFocus(index, event.code === "Backspace"); 227 } 228 229 word.deletionAttempts++; 230 } 231 } 232 else { 233 word.deletionAttempts = 0; 234 } 235 236 // Focus on the next word if the user is moving right with their caret at the word's end 250 if (event.code === "Spacebar" && word.length > 0) { 251 // - if at either edge, create new word before/after 252 // - else split word 253 } 254 255 // // Focus on the next word if the user is moving right with their caret at the word's end 237 256 // if (event.code === "ArrowRight") { 238 257 // const inputElement = this.$refs[word.id]; 239 258 240 259 // if (inputElement.selectionStart === word.word.length) { 241 // setFocus(false, this);260 // this.setFocus(index, false); 242 261 // } 243 262 // } 244 263 245 // Focus on the previous word if the user is moving left with their caret at the word's start264 // // Focus on the previous word if the user is moving left with their caret at the word's start 246 265 // if (event.code === "ArrowLeft") { 247 266 // const inputElement = this.$refs[word.id]; 248 267 249 268 // if (inputElement.selectionStart === 0) { 250 // setFocus(true, this);269 // this.setFocus(index, true); 251 270 // } 252 271 // }
Note:
See TracChangeset
for help on using the changeset viewer.