RESOLVED FIXED Bug 238621
Moving forwards and backwards by sentences across a table results in different breaks in each direction.
https://bugs.webkit.org/show_bug.cgi?id=238621
Summary Moving forwards and backwards by sentences across a table results in differen...
Megan Gardner
Reported 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.
Attachments
Sample page showing issue. (838 bytes, text/html)
2022-03-31 11:27 PDT, Megan Gardner
no flags
Patch (3.82 KB, patch)
2022-03-31 15:06 PDT, Megan Gardner
ews-feeder: commit-queue-
Patch (7.51 KB, patch)
2022-03-31 15:57 PDT, Megan Gardner
ews-feeder: commit-queue-
Patch (7.61 KB, patch)
2022-03-31 17:19 PDT, Megan Gardner
darin: review+
ews-feeder: commit-queue-
Patch (9.51 KB, patch)
2022-04-01 14:15 PDT, Megan Gardner
no flags
Patch for landing (9.51 KB, patch)
2022-04-05 00:16 PDT, Megan Gardner
no flags
Megan Gardner
Comment 1 2022-03-31 11:28:56 PDT
Megan Gardner
Comment 2 2022-03-31 15:06:55 PDT
Darin Adler
Comment 3 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.
Megan Gardner
Comment 4 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?
Megan Gardner
Comment 5 2022-03-31 15:57:25 PDT
Darin Adler
Comment 6 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.
Megan Gardner
Comment 7 2022-03-31 17:19:54 PDT
Darin Adler
Comment 8 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".
Darin Adler
Comment 9 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.
Megan Gardner
Comment 10 2022-04-01 14:15:42 PDT
Megan Gardner
Comment 11 2022-04-05 00:16:03 PDT
Created attachment 456677 [details] Patch for landing
EWS
Comment 12 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].
Note You need to log in before you can comment on or make changes to this bug.