File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -150,23 +150,29 @@ const selectEnd = (element: HTMLElement, position: number) => {
150150 if ( position === - 1 ) {
151151 range . setStart ( textNodes . slice ( - 1 ) [ 0 ] , Math . min ( position , element . textContent ?. length || 0 ) ) ;
152152 } else {
153+ const lastTextNode = textNodes . findLast ( ( node ) => node . nodeName === '#text' ) ;
154+
153155 textNodes . forEach ( ( node ) => {
154156 if ( position < 0 ) return ;
155157
156158 const length = node . nodeName === '#text'
157- ? node . textContent ?. length || 0
158- : 1 ;
159-
160- if ( node . nodeName === 'BR' ) {
161-
162- }
159+ ? node . textContent ?. length || 0
160+ : 1 ;
163161
164162 position -= length ;
165163
166- if ( position <= 0 ) {
164+ if ( position <= 0 || node === lastTextNode ) {
165+ console . log ( node ) ;
166+
167167 const index = Math . max ( Math . min ( position + length , length ) , 0 ) ;
168168
169- range . setStart ( node , index ) ;
169+ if ( node . textContent ?. at ( index - 1 ) === '\n' ) {
170+ range . setStart ( node , Math . max ( index - 1 , 0 ) ) ;
171+ } else {
172+ range . setStart ( node , index ) ;
173+ }
174+
175+ position = - 1 ;
170176 }
171177 } ) ;
172178 }
You can’t perform that action at this time.
0 commit comments