@@ -799,16 +799,22 @@ impl TextArea {
799
799
}
800
800
801
801
pub ( crate ) fn beginning_of_previous_word ( & self ) -> usize {
802
- if let Some ( first_non_ws) = self . text [ ..self . cursor_pos ] . rfind ( |c : char | !c. is_whitespace ( ) )
803
- {
804
- let candidate = self . text [ ..first_non_ws]
805
- . rfind ( |c : char | c. is_whitespace ( ) )
806
- . map ( |i| i + 1 )
807
- . unwrap_or ( 0 ) ;
808
- self . adjust_pos_out_of_elements ( candidate, true )
809
- } else {
810
- 0
811
- }
802
+ let prefix = & self . text [ ..self . cursor_pos ] ;
803
+ let Some ( ( first_non_ws_idx, _) ) = prefix
804
+ . char_indices ( )
805
+ . rev ( )
806
+ . find ( |& ( _, ch) | !ch. is_whitespace ( ) )
807
+ else {
808
+ return 0 ;
809
+ } ;
810
+ let before = & prefix[ ..first_non_ws_idx] ;
811
+ let candidate = before
812
+ . char_indices ( )
813
+ . rev ( )
814
+ . find ( |& ( _, ch) | ch. is_whitespace ( ) )
815
+ . map ( |( idx, ch) | idx + ch. len_utf8 ( ) )
816
+ . unwrap_or ( 0 ) ;
817
+ self . adjust_pos_out_of_elements ( candidate, true )
812
818
}
813
819
814
820
pub ( crate ) fn end_of_next_word ( & self ) -> usize {
@@ -1262,6 +1268,15 @@ mod tests {
1262
1268
assert_eq ! ( t. cursor( ) , 6 ) ;
1263
1269
}
1264
1270
1271
+ #[ test]
1272
+ fn delete_backward_word_handles_narrow_no_break_space ( ) {
1273
+ let mut t = ta_with ( "32\u{202F} AM" ) ;
1274
+ t. set_cursor ( t. text ( ) . len ( ) ) ;
1275
+ t. input ( KeyEvent :: new ( KeyCode :: Backspace , KeyModifiers :: ALT ) ) ;
1276
+ pretty_assertions:: assert_eq!( t. text( ) , "32\u{202F} " ) ;
1277
+ pretty_assertions:: assert_eq!( t. cursor( ) , t. text( ) . len( ) ) ;
1278
+ }
1279
+
1265
1280
#[ test]
1266
1281
fn delete_forward_word_with_without_alt_modifier ( ) {
1267
1282
let mut t = ta_with ( "hello world" ) ;
0 commit comments