File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -210,7 +210,13 @@ fn extend_single_word_in_comment_or_string(
210210 let start_idx = before. rfind ( non_word_char) ? as u32 ;
211211 let end_idx = after. find ( non_word_char) . unwrap_or ( after. len ( ) ) as u32 ;
212212
213- let from: TextSize = ( start_idx + 1 ) . into ( ) ;
213+ // FIXME: use `ceil_char_boundary` from `std::str` when it gets stable
214+ // https://github.com/rust-lang/rust/issues/93743
215+ fn ceil_char_boundary ( text : & str , index : u32 ) -> u32 {
216+ ( index..) . find ( |& index| text. is_char_boundary ( index as usize ) ) . unwrap_or ( text. len ( ) as u32 )
217+ }
218+
219+ let from: TextSize = ceil_char_boundary ( text, start_idx + 1 ) . into ( ) ;
214220 let to: TextSize = ( cursor_position + end_idx) . into ( ) ;
215221
216222 let range = TextRange :: new ( from, to) ;
@@ -662,4 +668,18 @@ fn main() { let (
662668 ] ,
663669 ) ;
664670 }
671+
672+ #[ test]
673+ fn extend_selection_inside_str_with_wide_char ( ) {
674+ // should not panic
675+ do_check (
676+ r#"fn main() { let x = "═$0═══════"; }"# ,
677+ & [
678+ r#""════════""# ,
679+ r#"let x = "════════";"# ,
680+ r#"{ let x = "════════"; }"# ,
681+ r#"fn main() { let x = "════════"; }"# ,
682+ ] ,
683+ ) ;
684+ }
665685}
You can’t perform that action at this time.
0 commit comments