| 15 | |
| 16 | // Set the input element's text, and move the cursor to the end. |
| 17 | function setTextInInputElement(inputEl, text) { |
| 18 | inputEl.textContent = text; |
| 19 | // Move the cursor to the end. Based on one of the solutions here: |
| 20 | // http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity |
| 21 | const range = document.createRange(); |
| 22 | range.selectNodeContents(inputEl); |
| 23 | range.collapse(false); |
| 24 | const selection = globalThis.getSelection(); |
| 25 | selection.removeAllRanges(); |
| 26 | selection.addRange(range); |
| 27 | } |
| 28 | |
| 29 | export function onKeyEvent(event) { |
| 30 | // Handle <Enter> on "keypress", and other events on "keydown"; this avoids interence with CJK |