File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed
Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change 1- const el = document . querySelector ( "#wordsInput" ) as HTMLInputElement ;
1+ const el = document . querySelector ( "#wordsInput" ) as HTMLTextAreaElement ;
22
33if ( el === null ) {
44 throw new Error ( "Words input element not found" ) ;
55}
66
7- export function getInputElement ( ) : HTMLInputElement {
7+ export function getInputElement ( ) : HTMLTextAreaElement {
88 return el ;
99}
1010
Original file line number Diff line number Diff line change @@ -20,20 +20,17 @@ inputEl.addEventListener("select selectstart", (event) => {
2020
2121inputEl . addEventListener ( "selectionchange" , ( event ) => {
2222 const selection = window . getSelection ( ) ;
23+
2324 console . debug ( "wordsInput event selectionchange" , {
2425 event,
2526 selection : selection ?. toString ( ) ,
2627 isCollapsed : selection ?. isCollapsed ,
27- selectionStart : ( event . target as HTMLInputElement ) . selectionStart ,
28- selectionEnd : ( event . target as HTMLInputElement ) . selectionEnd ,
28+ selectionStart : inputEl . selectionStart ,
29+ selectionEnd : inputEl . selectionEnd ,
2930 } ) ;
30- const el = event . target ;
31- if ( el === null || ! ( el instanceof HTMLInputElement ) ) {
32- return ;
33- }
3431
35- const hasSelectedText = el . selectionStart !== el . selectionEnd ;
36- const isCursorAtEnd = el . selectionStart === el . value . length ;
32+ const hasSelectedText = inputEl . selectionStart !== inputEl . selectionEnd ;
33+ const isCursorAtEnd = inputEl . selectionStart === inputEl . value . length ;
3734 if ( hasSelectedText || ! isCursorAtEnd ) {
3835 moveInputElementCaretToTheEnd ( ) ;
3936 }
You can’t perform that action at this time.
0 commit comments