(field: HTMLInputElement)
| 3 | * Return value range is 0-field.value.length. |
| 4 | */ |
| 5 | const getCaretPosition = (field: HTMLInputElement): number | null => { |
| 6 | // Initialize |
| 7 | let caretPos: number | null = 0; |
| 8 | |
| 9 | if (field.selectionStart || field.selectionStart === 0) { // Firefox support |
| 10 | caretPos = field.selectionDirection === "backward" ? field.selectionStart : field.selectionEnd; |
| 11 | } |
| 12 | |
| 13 | return caretPos; |
| 14 | }; |
| 15 | |
| 16 | const setCaretPosition = (field: HTMLInputElement, caretPos: number | null) => { |
| 17 | if (field.selectionStart) { |
no outgoing calls
no test coverage detected
searching dependent graphs…