@@ -31,8 +31,8 @@ pub struct Subject<'a: 'd, 'r, 'o, 'c, 'd, 'i> {
3131 pub input : & ' i [ u8 ] ,
3232 line : usize ,
3333 pub pos : usize ,
34- block_offset : usize ,
3534 column_offset : isize ,
35+ line_offset : usize ,
3636 flags : Flags ,
3737 pub refmap : & ' r mut RefMap ,
3838 delimiter_arena : & ' d Arena < Delimiter < ' a , ' d > > ,
@@ -116,7 +116,6 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
116116 options : & ' o Options < ' c > ,
117117 input : & ' i [ u8 ] ,
118118 line : usize ,
119- block_offset : usize ,
120119 refmap : & ' r mut RefMap ,
121120 delimiter_arena : & ' d Arena < Delimiter < ' a , ' d > > ,
122121 ) -> Self {
@@ -126,8 +125,8 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
126125 input,
127126 line,
128127 pos : 0 ,
129- block_offset,
130128 column_offset : 0 ,
129+ line_offset : 0 ,
131130 flags : Flags :: default ( ) ,
132131 refmap,
133132 delimiter_arena,
@@ -182,6 +181,11 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
182181 None => return false ,
183182 Some ( ch) => * ch as char ,
184183 } ;
184+
185+ let node_ast = node. data . borrow ( ) ;
186+ let adjusted_line = self . line - node_ast. sourcepos . start . line ;
187+ self . line_offset = * node_ast. line_offsets . get ( adjusted_line) . unwrap_or ( & 0 ) ;
188+
185189 let new_inl: Option < & ' a AstNode < ' a > > = match c {
186190 '\0' => return false ,
187191 '\r' | '\n' => Some ( self . handle_newline ( ) ) ,
@@ -1604,7 +1608,7 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
16041608 inl. data . borrow_mut ( ) . sourcepos . start . column =
16051609 bracket_inl_text. data . borrow ( ) . sourcepos . start . column ;
16061610 inl. data . borrow_mut ( ) . sourcepos . end . column = usize:: try_from (
1607- self . pos as isize + self . column_offset + self . block_offset as isize ,
1611+ self . pos as isize + self . column_offset + self . line_offset as isize ,
16081612 )
16091613 . unwrap ( ) ;
16101614 bracket_inl_text. insert_before ( inl) ;
@@ -1655,7 +1659,7 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
16551659 . sourcepos
16561660 . start ;
16571661 inl. data . borrow_mut ( ) . sourcepos . end . column =
1658- usize:: try_from ( self . pos as isize + self . column_offset + self . block_offset as isize )
1662+ usize:: try_from ( self . pos as isize + self . column_offset + self . line_offset as isize )
16591663 . unwrap ( ) ;
16601664
16611665 self . brackets [ brackets_len - 1 ] . inl_text . insert_before ( inl) ;
@@ -1847,8 +1851,8 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
18471851 end_column : usize ,
18481852 ) -> & ' a AstNode < ' a > {
18491853 let start_column =
1850- start_column as isize + 1 + self . column_offset + self . block_offset as isize ;
1851- let end_column = end_column as isize + 1 + self . column_offset + self . block_offset as isize ;
1854+ start_column as isize + 1 + self . column_offset + self . line_offset as isize ;
1855+ let end_column = end_column as isize + 1 + self . column_offset + self . line_offset as isize ;
18521856
18531857 let ast = Ast {
18541858 value,
@@ -1864,6 +1868,7 @@ impl<'a, 'r, 'o, 'c, 'd, 'i> Subject<'a, 'r, 'o, 'c, 'd, 'i> {
18641868 open : false ,
18651869 last_line_blank : false ,
18661870 table_visited : false ,
1871+ line_offsets : Vec :: new ( ) ,
18671872 } ;
18681873 self . arena . alloc ( Node :: new ( RefCell :: new ( ast) ) )
18691874 }
@@ -1972,6 +1977,7 @@ pub fn make_inline<'a>(
19721977 open : false ,
19731978 last_line_blank : false ,
19741979 table_visited : false ,
1980+ line_offsets : Vec :: new ( ) ,
19751981 } ;
19761982 arena. alloc ( Node :: new ( RefCell :: new ( ast) ) )
19771983}
0 commit comments