Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#57788 closed enhancement (fixed)

HTML Tag Processor: Add bookmark invalidation logic

Reported by: Bernhard Reiter Owned by: hellofromTonya
Priority: normal Milestone: 6.3
Component: HTML API Version:
Severity: normal Keywords: has-patch gutenberg-merge has-unit-tests commit
Cc: Focuses:

Description

While WP_HTML_Tag_Processor currently only supports changing a given tag's attributes, we plan to also provide methods to make broader changes (possibly through a subclass of WP_HTML_Tag_Processor).

An API like that will have the potential of replacing a tag that a bookmark points to. As a preparation, we thus need to make sure that all bookmarks affected by a HTML replacement are invalidated (i.e. released).

Change History (10)

This ticket was mentioned in ​PR #4116 on ​WordPress/wordpress-develop by ​@Bernhard Reiter.


4 years ago
#1

  • Keywords has-patch added

While WP_HTML_Tag_Processor currently only supports changing a given tag's attributes, we plan to also provide methods to make broader changes (possibly through a subclass of WP_HTML_Tag_Processor).
An API like that will have the potential of replacing a tag that a bookmark points to. As a preparation, we thus need to make sure that all bookmarks affected by a HTML replacement are invalidated (i.e. released).

This is done by extending the existing loop in apply_attributes_updates that adjusts bookmarks' start and end positions upon HTML changes to check if the entire bookmark is within a portion of the HTML that has been replaced.

Note that this PR is a backport of ​https://github.com/WordPress/gutenberg/pull/47559.

Trac ticket: https://core.trac.wordpress.org/ticket/57788

​@Bernhard Reiter commented on ​PR #4116:


4 years ago
#2

cc/ @dmsnell 😊

#3 @hellofromTonya
4 years ago

  • Keywords gutenberg-merge added

​@Bernhard Reiter commented on ​PR #4116:


4 years ago
#4

Thank you! 😊

Just noting that we can't merge this to trunk until Core is comes out of the 6.2 Beta phase, which ​should happen on March 7.

#5 @hellofromTonya
4 years ago

  • Keywords has-unit-tests commit added
  • Owner set to hellofromTonya
  • Status new → reviewing

Patch:

Ready for commit 👍 Prepping commit now.

​@hellofromTonya commented on ​PR #4116:


4 years ago
#6

Prepping commit now ✅

#7 @hellofromTonya
4 years ago

  • Resolution → fixed
  • Status reviewing → closed

In 55555:

HTML API: Add bookmark invalidation logic.

While WP_HTML_Tag_Processor currently only supports changing a given tag's attributes, the plan is to provide methods to make broader changes (possibly through a subclass of WP_HTML_Tag_Processor). The API will have the potential of replacing a tag that a bookmark points to. To prepare, this changeset makes sure that all bookmarks affected by a HTML replacement are invalidated (i.e. released).

Changes:

  • Extends the existing loop in WP_HTML_Tag_Processor::apply_attributes_updates() that adjusts bookmarks' start and end positions upon HTML changes to check if the entire bookmark is within a portion of the HTML that has been replaced.
  • Adds `WP_HTML_Tag_Processor::has_bookmark() to check whether the given bookmark name exists.

References:

Follow-up to [55203].

Props bernhard-reiter, dmsnell, zieladam.
Fixes #57788.

#9 @SergeyBiryukov
4 years ago

  • Component Editor → HTML API

​@Bernhard Reiter commented on ​PR #4116:


4 years ago
#10

Thank you very much for landing this @hellofromtonya !

Note: See TracTickets for help on using tickets.