Make WordPress Core

Opened 22 months ago

Closed 21 months ago

Last modified 21 months ago

#57788 closed enhancement (fixed)

HTML Tag Processor: Add bookmark invalidation logic

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

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.


22 months 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:


22 months ago
#2

cc/ @dmsnell 😊

#3 @hellofromTonya
22 months ago

  • Keywords gutenberg-merge added

@Bernhard Reiter commented on PR #4116:


22 months 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
21 months ago

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

Patch:

Ready for commit 👍 Prepping commit now.

@hellofromTonya commented on PR #4116:


21 months ago
#6

Prepping commit now ✅

#7 @hellofromTonya
21 months ago

  • Resolution set to fixed
  • Status changed from reviewing to 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
21 months ago

  • Component changed from Editor to HTML API

@Bernhard Reiter commented on PR #4116:


21 months ago
#10

Thank you very much for landing this @hellofromtonya !

Note: See TracTickets for help on using tickets.