@@ -302,6 +302,7 @@ impl TextInputComponent {
302
302
303
303
let mut dist =
304
304
self . get_real_distance ( line_start, self . cursor_position ) ;
305
+
305
306
self . cursor_position = line_end;
306
307
307
308
if line_start != 0 {
@@ -314,25 +315,20 @@ impl TextInputComponent {
314
315
fn get_real_distance ( & self , start : usize , end : usize ) -> usize {
315
316
let mut index = start;
316
317
let mut dist = 0 ;
317
- while index < end {
318
+ while index <= end {
318
319
if self . msg . is_char_boundary ( index) {
319
320
dist += 1 ;
320
321
}
321
322
index += 1 ;
322
323
}
323
- dist + 1
324
+ dist
324
325
}
325
326
326
- /// Move forward `distance` amount of charachters stopping at a newline
327
+ /// Move forward `distance` amount of characters stopping at a newline
327
328
fn cursor_forward ( & mut self , distance : usize ) {
328
329
let mut travelled = 0 ;
329
330
let mut index = self . cursor_position ;
330
331
while index < self . msg . len ( ) + 1 {
331
- if index == self . msg . len ( ) - 1 {
332
- self . cursor_position = index + 1 ;
333
- break ;
334
- }
335
-
336
332
if self . msg . is_char_boundary ( index) {
337
333
travelled += 1 ;
338
334
}
@@ -342,6 +338,11 @@ impl TextInputComponent {
342
338
break ;
343
339
}
344
340
341
+ if index == self . msg . len ( ) - 1 {
342
+ self . cursor_position = index + 1 ;
343
+ break ;
344
+ }
345
+
345
346
index += 1 ;
346
347
347
348
if index != self . msg . len ( ) - 1
@@ -897,7 +898,7 @@ mod tests {
897
898
false ,
898
899
) ;
899
900
900
- comp. set_text ( String :: from ( "aaaaa\n äaa\n aaa" ) ) ;
901
+ comp. set_text ( String :: from ( "aaaaa\n äaa\n aaa\n aaa " ) ) ;
901
902
902
903
comp. cursor_position = 0 ;
903
904
comp. cursor_down ( ) ;
@@ -915,6 +916,10 @@ mod tests {
915
916
comp. cursor_down ( ) ;
916
917
assert_eq ! ( comp. cursor_position, 12 ) ;
917
918
919
+ comp. cursor_position = 13 ;
920
+ comp. cursor_down ( ) ;
921
+ assert_eq ! ( comp. cursor_position, 17 ) ;
922
+
918
923
comp. cursor_position = 6 ;
919
924
comp. cursor_up ( ) ;
920
925
assert_eq ! ( comp. cursor_position, 0 ) ;
0 commit comments