@@ -940,9 +940,20 @@ impl<'a> CursorLines<'a> {
940940
941941#[ derive( Copy , Clone , Debug , PartialEq ) ]
942942pub ( crate ) enum EndLine {
943- Eof = 0 ,
944- Crlf = 1 ,
945- Lf = 2 ,
943+ Eof ,
944+ Lf ,
945+ Crlf ,
946+ }
947+
948+ impl EndLine {
949+ /// The number of characters this line ending occupies in bytes.
950+ pub ( crate ) fn len ( self ) -> usize {
951+ match self {
952+ EndLine :: Eof => 0 ,
953+ EndLine :: Lf => 1 ,
954+ EndLine :: Crlf => 2 ,
955+ }
956+ }
946957}
947958
948959impl < ' a > Iterator for CursorLines < ' a > {
@@ -957,12 +968,12 @@ impl<'a> Iterator for CursorLines<'a> {
957968 . map ( |x| {
958969 let ret = if 0 < x {
959970 if self . 0 . as_bytes ( ) [ x - 1 ] == b'\r' {
960- ( & self . 0 [ ..x - 1 ] , EndLine :: Lf )
971+ ( & self . 0 [ ..x - 1 ] , EndLine :: Crlf )
961972 } else {
962- ( & self . 0 [ ..x] , EndLine :: Crlf )
973+ ( & self . 0 [ ..x] , EndLine :: Lf )
963974 }
964975 } else {
965- ( "" , EndLine :: Crlf )
976+ ( "" , EndLine :: Lf )
966977 } ;
967978 self . 0 = & self . 0 [ x + 1 ..] ;
968979 ret
@@ -1138,7 +1149,7 @@ fn format_header<'a>(
11381149 ..
11391150 } = item
11401151 {
1141- if main_range >= range. 0 && main_range <= range. 1 + * end_line as usize {
1152+ if main_range >= range. 0 && main_range <= range. 1 + end_line. len ( ) {
11421153 let char_column = text[ 0 ..( main_range - range. 0 ) . min ( text. len ( ) ) ]
11431154 . chars ( )
11441155 . count ( ) ;
@@ -1366,7 +1377,7 @@ fn format_body(
13661377 for ( idx, ( line, end_line) ) in CursorLines :: new ( snippet. source ) . enumerate ( ) {
13671378 let line_length: usize = line. len ( ) ;
13681379 let line_range = ( current_index, current_index + line_length) ;
1369- let end_line_size = end_line as usize ;
1380+ let end_line_size = end_line. len ( ) ;
13701381 body. push ( DisplayLine :: Source {
13711382 lineno : Some ( current_line) ,
13721383 inline_marks : vec ! [ ] ,
0 commit comments