Make WordPress Core

Opened 16 months ago

Closed 16 months ago

Last modified 14 months ago

#59993 closed enhancement (fixed)

HTML API: Track spans of text with (offset, length) instead of (start, end)

Reported by: dmsnell's profile dmsnell Owned by: zieladam's profile zieladam
Milestone: 6.5 Priority: normal
Severity: normal Version: 6.5
Component: HTML API Keywords: has-patch needs-dev-note
Focuses: Cc:

Description

This patch follows-up with earlier design questions around how to represent spans of strings inside the class. It's relevant now as preparation for #5683.

The mixture of (offset, length) and (start, end) coordinates becomes confusing at times and all final string operations are performed with the (offset, length) pair, since these feed into strlen().

In preparation for exposing all tokens within an HTML document this change:

Unifies the representation throughout the class.
It creates token_starts_at to track the start of the current token.
It replaces tag_ends_at with token_length for re-use with other token types.
There should be no functional or behavioral changes in this patch.

For the internal helper classes this patch introduces breaking changes, but those classes are marked private and should not be used outside of the HTML API itself.

Change History (5)

#1 @zieladam
16 months ago

  • Owner set to zieladam
  • Resolution set to fixed
  • Status changed from new to closed

In 57179:

HTML API: Track spans of text with (offset, length) instead of (start, end).

Updates the internal representation of the text span coordinates. The mixture of (offset, length) and (start, end) coordinates becomes confusing, this commit replaces it with a (offset, length) pair. There should be no functional or behavioral changes in this patch. For the internal helper classes this patch introduces breaking changes, but those classes are marked private and should not be used outside of the HTML API itself.

Props dmsnell.
Fixes #59993.

#2 @david.binda
15 months ago

I have noticed that this changeset leads to PHP Fatal errors when used with the latest Gutenberg plugin ( tested with 17.2.3 and 17.3.0 RC1 ) as the plugin is extending some of the affected classes and is expecting the original properties (start, end).

I have reported the issue in Gutenberg repository ( https://github.com/WordPress/gutenberg/issues/57216 ), but wanted to flag it here as well despite the commit description mentioning the breaking changes.

#3 @kebbet
14 months ago

With changeset in trunk during 6.5, please milestone the ticket to 6.5 @zieladam, thanks!

#4 @dmsnell
14 months ago

  • Milestone changed from Awaiting Review to 6.5

thanks @kebbet - I've set the milestone to 6.5

#5 @stevenlinx
14 months ago

  • Keywords needs-dev-note added

as part of a standalone dev note post

Note: See TracTickets for help on using tickets.