@@ -11,7 +11,7 @@ use web_sys::{
1111 window, Document , Element , Window ,
1212} ;
1313
14- use crate :: { backend:: utils:: * , error:: Error , widgets :: hyperlink :: HYPERLINK_MODIFIER } ;
14+ use crate :: { backend:: utils:: * , error:: Error } ;
1515
1616/// Options for the [`DomBackend`].
1717#[ derive( Debug , Default ) ]
@@ -30,7 +30,7 @@ impl DomBackendOptions {
3030 ///
3131 /// - If the grid ID is not set, it returns `"grid"`.
3232 /// - If the grid ID is set, it returns the grid ID suffixed with
33- /// `"_ratzilla_grid"`.
33+ /// `"_ratzilla_grid"`.
3434 pub fn grid_id ( & self ) -> String {
3535 match & self . grid_id {
3636 Some ( id) => format ! ( "{id}_ratzilla_grid" ) ,
@@ -131,30 +131,10 @@ impl DomBackend {
131131 fn prerender ( & mut self ) -> Result < ( ) , Error > {
132132 for line in self . buffer . iter ( ) {
133133 let mut line_cells: Vec < Element > = Vec :: new ( ) ;
134- let mut hyperlink: Vec < Cell > = Vec :: new ( ) ;
135- for ( i, cell) in line. iter ( ) . enumerate ( ) {
136- if cell. modifier . contains ( HYPERLINK_MODIFIER ) {
137- hyperlink. push ( cell. clone ( ) ) ;
138- // If the next cell is not part of the hyperlink, close it
139- if !line
140- . get ( i + 1 )
141- . map ( |c| c. modifier . contains ( HYPERLINK_MODIFIER ) )
142- . unwrap_or ( false )
143- {
144- let anchor = create_anchor ( & self . document , & hyperlink) ?;
145- for link_cell in & hyperlink {
146- let span = create_span ( & self . document , link_cell) ?;
147- self . cells . push ( span. clone ( ) ) ;
148- anchor. append_child ( & span) ?;
149- }
150- line_cells. push ( anchor) ;
151- hyperlink. clear ( ) ;
152- }
153- } else {
154- let span = create_span ( & self . document , cell) ?;
155- self . cells . push ( span. clone ( ) ) ;
156- line_cells. push ( span) ;
157- }
134+ for cell in line. iter ( ) {
135+ let span = create_span ( & self . document , cell) ?;
136+ self . cells . push ( span. clone ( ) ) ;
137+ line_cells. push ( span) ;
158138 }
159139
160140 // Create a <pre> element for the line
@@ -176,13 +156,20 @@ impl DomBackend {
176156 fn update_grid ( & mut self ) -> Result < ( ) , Error > {
177157 for ( y, line) in self . buffer . iter ( ) . enumerate ( ) {
178158 for ( x, cell) in line. iter ( ) . enumerate ( ) {
179- if cell. modifier . contains ( HYPERLINK_MODIFIER ) {
180- continue ;
181- }
182159 if cell != & self . prev_buffer [ y] [ x] {
183160 let elem = self . cells [ y * self . buffer [ 0 ] . len ( ) + x] . clone ( ) ;
184- elem. set_inner_html ( cell. symbol ( ) ) ;
185161 elem. set_attribute ( "style" , & get_cell_style_as_css ( cell) ) ?;
162+ if let Some ( anchor) = elem. first_element_child ( ) {
163+ if let Some ( url) = cell. hyperlink ( ) {
164+ anchor. set_attribute ( "href" , url) ?;
165+ anchor. set_inner_html ( cell. symbol ( ) ) ;
166+ } else {
167+ anchor. remove ( ) ;
168+ elem. set_inner_html ( cell. symbol ( ) ) ;
169+ }
170+ } else {
171+ elem. set_inner_html ( cell. symbol ( ) ) ;
172+ }
186173 }
187174 }
188175 }
0 commit comments