File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -150,23 +150,29 @@ const selectEnd = (element: HTMLElement, position: number) => {
150
150
if ( position === - 1 ) {
151
151
range . setStart ( textNodes . slice ( - 1 ) [ 0 ] , Math . min ( position , element . textContent ?. length || 0 ) ) ;
152
152
} else {
153
+ const lastTextNode = textNodes . findLast ( ( node ) => node . nodeName === '#text' ) ;
154
+
153
155
textNodes . forEach ( ( node ) => {
154
156
if ( position < 0 ) return ;
155
157
156
158
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 ;
163
161
164
162
position -= length ;
165
163
166
- if ( position <= 0 ) {
164
+ if ( position <= 0 || node === lastTextNode ) {
165
+ console . log ( node ) ;
166
+
167
167
const index = Math . max ( Math . min ( position + length , length ) , 0 ) ;
168
168
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 ;
170
176
}
171
177
} ) ;
172
178
}
You can’t perform that action at this time.
0 commit comments