Bug 238621 - Moving forwards and backwards by sentences across a table results in different breaks in each direction.
Summary: Moving forwards and backwards by sentences across a table results in differen...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Megan Gardner
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-03-31 11:27 PDT by Megan Gardner
Modified: 2022-04-05 01:03 PDT (History)
3 users (show)

See Also:


Attachments
Sample page showing issue. (838 bytes, text/html)
2022-03-31 11:27 PDT, Megan Gardner
no flags Details
Patch (3.82 KB, patch)
2022-03-31 15:06 PDT, Megan Gardner
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (7.51 KB, patch)
2022-03-31 15:57 PDT, Megan Gardner
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (7.61 KB, patch)
2022-03-31 17:19 PDT, Megan Gardner
darin: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (9.51 KB, patch)
2022-04-01 14:15 PDT, Megan Gardner
no flags Details | Formatted Diff | Diff
Patch for landing (9.51 KB, patch)
2022-04-05 00:16 PDT, Megan Gardner
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Megan Gardner 2022-03-31 11:27:48 PDT
Created attachment 456260 [details]
Sample page showing issue.

Summary:
Moving by sentence across a table results in different breaks in each direction.

Steps To Reproduce:
1. Load up attached test page in Safari.
2. Click at the beginning of the table.
3. Press the ‘forward sentence’ button.
4. Note that the caret is after the table now
5. Press the ‘backward sentence’ button.
6. Note that it stops at the front of each cell.

Results:
The results should be the same in each direction.

Regression:
I’m not sure this has ever worked. But we are running into issues more now that we’re trying to get more context for autocorrection.
Comment 1 Megan Gardner 2022-03-31 11:28:56 PDT
rdar://91115769
Comment 2 Megan Gardner 2022-03-31 15:06:55 PDT
Created attachment 456290 [details]
Patch
Comment 3 Darin Adler 2022-03-31 15:47:44 PDT
Comment on attachment 456290 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=456290&action=review

> Source/WebCore/ChangeLog:8
> +        Writing a test while checking this against the bots.

Looking forward to significant test coverage to this under-tested code.

Besides the sentence move testing, we should test the backwards text iterator directly using the internals.rangeAsTextUsingBackwardsTextIterator function. I think we could make some really good coverage of all sorts of cases that way.

> Source/WebCore/editing/TextIterator.cpp:1370
> +    if (shouldEmitTabBeforeNode(*m_node)) {
> +        // It is important to emit tabs in tables, so we need to make sure to emit those explicitly instead of just defaulting to linefeed breaks in order to traverse it correctly.
> +        unsigned index = m_node->computeNodeIndex();
> +        emitCharacter('\t', *m_node->parentNode(), index + 1, index + 1);
> +    }

To match the logic in the forward iterator, this tab check should be done first, and we should use else and only do the newline if we didn’t already do the tab.

The comments in the code about newlines above apply to tabs as well, so the comment should be copied and pasted, or we should refactor to share code.

I’m not sure we need the new comment saying "It is important to emit tabs in tables". It seems really straightforward to say that if shouldEmitTabBeforeNode is true, we should emit a tab. Seems more that we need a comment if we did not do that!

> Source/WebCore/editing/TextIterator.cpp:1385
> +    if (shouldEmitTabBeforeNode(*m_node)) {
> +        // It is important to emit tabs in tables, so we need to make sure to emit those explicitly instead of just defaulting to linefeed breaks in order to traverse it correctly.
> +        emitCharacter('\t', *m_node, 0, 0);
> +    }

Ditto, all the same comments apply.
Comment 4 Megan Gardner 2022-03-31 15:54:40 PDT
Comment on attachment 456290 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=456290&action=review

>> Source/WebCore/editing/TextIterator.cpp:1370
>> +    }
> 
> To match the logic in the forward iterator, this tab check should be done first, and we should use else and only do the newline if we didn’t already do the tab.
> 
> The comments in the code about newlines above apply to tabs as well, so the comment should be copied and pasted, or we should refactor to share code.
> 
> I’m not sure we need the new comment saying "It is important to emit tabs in tables". It seems really straightforward to say that if shouldEmitTabBeforeNode is true, we should emit a tab. Seems more that we need a comment if we did not do that!

I'm not sure what you mean by "The comments in the code about newlines above apply to tabs as well, so the comment should be copied and pasted, or we should refactor to share code." can you elaborate/specify?
Comment 5 Megan Gardner 2022-03-31 15:57:25 PDT
Created attachment 456294 [details]
Patch
Comment 6 Darin Adler 2022-03-31 16:08:41 PDT
Comment on attachment 456290 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=456290&action=review

>>> Source/WebCore/editing/TextIterator.cpp:1370
>>> +    }
>> 
>> To match the logic in the forward iterator, this tab check should be done first, and we should use else and only do the newline if we didn’t already do the tab.
>> 
>> The comments in the code about newlines above apply to tabs as well, so the comment should be copied and pasted, or we should refactor to share code.
>> 
>> I’m not sure we need the new comment saying "It is important to emit tabs in tables". It seems really straightforward to say that if shouldEmitTabBeforeNode is true, we should emit a tab. Seems more that we need a comment if we did not do that!
> 
> I'm not sure what you mean by "The comments in the code about newlines above apply to tabs as well, so the comment should be copied and pasted, or we should refactor to share code." can you elaborate/specify?

You copied the code, calling computeNodeIndex and emitCharacter, but not the comments that explain why we call computeNodeIndex ("Corresponds to the same check in TextIterator::exitNode") or gives context to emitCharacter ("The start of this emitted range is wrong [...]"). Need to copy the comments if copying the code.
Comment 7 Megan Gardner 2022-03-31 17:19:54 PDT
Created attachment 456299 [details]
Patch
Comment 8 Darin Adler 2022-03-31 17:26:50 PDT
Comment on attachment 456299 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=456299&action=review

I think we should add a lot more backwards text iterator tests instead of only testing it indirectly like this. But maybe not in this patch I guess.

> Source/WebCore/editing/TextIterator.cpp:1356
> +    

Should drop that that blank line.

> Source/WebCore/editing/TextIterator.cpp:1364
> +        // A linefeed breaks words, sentences, and paragraphs.

I know you kept this comment cut down from the longer old one. But the code is now doing something so obvious I think we can leave even this out. Basically code now says "if we should emit a newline, emit a newline".
Comment 9 Darin Adler 2022-03-31 21:22:54 PDT
Comment on attachment 456299 [details]
Patch

Looks like the change affected the result of editing/text-iterator/backwards-text-iterator-basic.html; that test probably needs to change.
Comment 10 Megan Gardner 2022-04-01 14:15:42 PDT
Created attachment 456401 [details]
Patch
Comment 11 Megan Gardner 2022-04-05 00:16:03 PDT
Created attachment 456677 [details]
Patch for landing
Comment 12 EWS 2022-04-05 01:03:00 PDT
Committed r292381 (249246@main): <https://commits.webkit.org/249246@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 456677 [details].