@@ -5286,8 +5286,6 @@ public function seek( $bookmark_name ): bool {
52865286 // Flush any pending updates to the document before beginning.
52875287 $ this ->get_updated_html ();
52885288
5289- echo 'Seeking to ' . $ bookmark_name . "\n" ;
5290-
52915289 $ actual_bookmark_name = "_ {$ bookmark_name }" ;
52925290 $ processor_started_at = $ this ->state ->current_token
52935291 ? $ this ->bookmarks [ $ this ->state ->current_token ->bookmark_name ]->start
@@ -5325,8 +5323,8 @@ public function seek( $bookmark_name ): bool {
53255323 * and computation time.
53265324 */
53275325 if ( 'backward ' === $ direction ) {
5328- echo 'back: ' . "\n" ;
53295326 // Reset necessary parser state
5327+ $ this ->change_parsing_namespace ( 'html ' );
53305328 $ this ->state ->frameset_ok = true ;
53315329 $ this ->state ->stack_of_template_insertion_modes = array ();
53325330 $ this ->state ->head_element = null ;
@@ -5335,64 +5333,55 @@ public function seek( $bookmark_name ): bool {
53355333 $ this ->element_queue = array ();
53365334 $ this ->current_element = null ;
53375335
5338- if ( null === $ this -> context_node ) {
5339- echo ' full parser' . "\n" ;
5340- /*
5341- * In the case of a full parser, the processor needs to be
5342- * reset to a clean state and start over.
5343- */
5344- $ this -> state -> stack_of_open_elements = new WP_HTML_Open_Elements ();
5345- $ this -> state -> active_formatting_elements = new WP_HTML_Active_Formatting_Elements () ;
5346- $ this -> state -> insertion_mode = WP_HTML_Processor_State:: INSERTION_MODE_INITIAL ;
5336+ /*
5337+ * In case the parser is a fragment parser, instead of clearing the
5338+ * parser state and starting fresh, calling the stack methods
5339+ * maintains the proper flags in the parser.
5340+ */
5341+ foreach ( $ this -> state -> stack_of_open_elements -> walk_up () as $ item ) {
5342+ if ( ' context-node ' === $ item -> bookmark_name ) {
5343+ break ;
5344+ }
53475345
5348- $ this ->breadcrumbs = array ();
5349- $ this ->bytes_already_parsed = 0 ;
5350- $ this ->parser_state = self ::STATE_READY ;
5351- } else {
5352- /*
5353- * In case the parser is a fragment parser, instead of clearing the
5354- * parser state and starting fresh, calling the stack methods
5355- * maintains the proper flags in the parser.
5356- */
5357- foreach ( $ this ->state ->stack_of_open_elements ->walk_up () as $ item ) {
5358- if ( 'context-node ' === $ item ->bookmark_name ) {
5359- break ;
5360- }
5346+ $ this ->state ->stack_of_open_elements ->remove_node ( $ item );
5347+ }
53615348
5362- $ this ->state ->stack_of_open_elements ->remove_node ( $ item );
5349+ foreach ( $ this ->state ->active_formatting_elements ->walk_up () as $ item ) {
5350+ if ( 'context-node ' === $ item ->bookmark_name ) {
5351+ break ;
53635352 }
53645353
5365- foreach ( $ this ->state ->active_formatting_elements ->walk_up () as $ item ) {
5366- if ( 'context-node ' === $ item ->bookmark_name ) {
5367- break ;
5368- }
5354+ $ this ->state ->active_formatting_elements ->remove_node ( $ item );
5355+ }
53695356
5370- $ this ->state ->active_formatting_elements ->remove_node ( $ item );
5371- }
5357+ if ( null === $ this ->context_node ) {
5358+ $ this ->state ->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_INITIAL ;
5359+ $ this ->breadcrumbs = array ();
53725360
5361+ $ this ->bytes_already_parsed = 0 ;
5362+ $ this ->parser_state = self ::STATE_READY ;
5363+ } else {
53735364 parent ::seek ( 'context-node ' );
53745365 $ this ->state ->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY ;
53755366 $ this ->breadcrumbs = array_slice ( $ this ->breadcrumbs , 0 , 2 );
53765367 }
53775368 }
53785369
5379-
53805370 // When moving forwards, reparse the document until reaching the same location as the original bookmark.
53815371 if ( null !== $ this ->state ->current_token && $ bookmark_starts_at === $ this ->bookmarks [ $ this ->state ->current_token ->bookmark_name ]->start ) {
53825372 return true ;
53835373 }
53845374
5385- while ( var_dump ( $ this ->next_token () ) ) {
5386- echo ' bm starts at ' . $ bookmark_starts_at . ' and current token starts at ' . $ this ->bookmarks [ $ this ->state -> current_token ->bookmark_name ]-> start . "\n" ;
5387- if ( $ bookmark_starts_at === $ this -> bookmarks [ $ this -> state -> current_token -> bookmark_name ] ->start ) {
5375+ while ( $ this ->next_token () ) {
5376+ $ bm = $ this ->bookmarks [ $ this ->current_element -> token ->bookmark_name ];
5377+ if ( $ bookmark_starts_at === $ bm ->start ) {
53885378 while ( isset ( $ this ->current_element ) && WP_HTML_Stack_Event::POP === $ this ->current_element ->operation ) {
53895379 $ this ->current_element = array_shift ( $ this ->element_queue );
53905380 }
53915381 return true ;
53925382 }
53935383 }
53945384
5395- echo 'false ' . "\n" ;
53965385 return false ;
53975386 }
53985387
0 commit comments