[webkit-changes] [WebKit/WebKit] addeb5: [Writing Tools] Text underneath replaced range doe...

Aditya Keerthi noreply at github.com
Mon Sep 16 14:28:21 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: addeb52fffc6561775b2304d98b161c55bc2d3aa
      https://github.com/WebKit/WebKit/commit/addeb52fffc6561775b2304d98b161c55bc2d3aa
  Author: Aditya Keerthi <akeerthi at apple.com>
  Date:   2024-09-16 (Mon, 16 Sep 2024)

  Changed paths:
    M Source/WebCore/editing/WritingToolsCompositionCommand.cpp
    M Source/WebCore/editing/WritingToolsCompositionCommand.h
    M Source/WebCore/page/writing-tools/WritingToolsController.h
    M Source/WebCore/page/writing-tools/WritingToolsController.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingTools.mm

  Log Message:
  -----------
  [Writing Tools] Text underneath replaced range does not animate smoothly
https://bugs.webkit.org/show_bug.cgi?id=279600
rdar://135741279

Reviewed by Richard Robinson.

Writing Tools supplies text to its delegate using
`-[WTWritingToolsDelegate compositionSession:didReceiveText:replacementRange:inContext:finished:]`.
However, the last replacement can end up calling the method twice with the same
content, varying only the finished parameter.

This is problematic for the animations, as an animation is only initiated on
the first call with `finished=false`, but both calls perform the same
replacement. The second, redundant, replacement results in text being modified
before the animation is complete, resulting in a bad animation.

Fix by removing the redundant replacement.

* Source/WebCore/editing/WritingToolsCompositionCommand.cpp:
(WebCore::WritingToolsCompositionCommand::replaceContentsOfRangeWithFragment):
(WebCore::WritingToolsCompositionCommand::commit):
* Source/WebCore/editing/WritingToolsCompositionCommand.h:
* Source/WebCore/page/writing-tools/WritingToolsController.h:
* Source/WebCore/page/writing-tools/WritingToolsController.mm:
(WebCore::WritingToolsController::compositionSessionDidReceiveTextWithReplacementRangeAsync):

Commit the command immediately after performing replacement if the finished flag was
observed with the same range.

(WebCore::WritingToolsController::compositionSessionDidReceiveTextWithReplacementRange):

If `finished` is true and the same replaced range is observed, simply commit
the overall replacement to the undo stack, and skip animations and redundant
replacement.

This is correct as replaced ranges will always have the same prefix. Additionally,
comparing to the replaced range keeps the logic robust against clients that
only send `finished=true` for the last replacement without a `finished=false`,
such as smart replies.

If the `finished` flag comes in while the same range is still pending application,
the command will be committed in `compositionSessionDidReceiveTextWithReplacementRangeAsync`.

(WebCore::WritingToolsController::restartCompositionForSession):

Reset the replaced range when a composition is restarted.

(WebCore::WritingToolsController::commitComposition):

Helper method to apply the command to the undo stack.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingTools.mm:

Adjust tests to use the delegate in the same way that Writing Tools does.

(TEST(WritingTools, CompositionWithAttemptedEditing)):
(TEST(WritingTools, Composition)):
(TEST(WritingTools, CompositionRevert)):
(TEST(WritingTools, CompositionWithAttributedStringAttributes)):
(TEST(WritingTools, CompositionWithList)):
(TEST(WritingTools, CompositionWithTextAttachment)):
(TEST(WritingTools, CompositionWithNonImageAttachmentRoundTrip)):
(TEST(WritingTools, CompositionWithMultipleChunks)):
(TEST(WritingTools, CompositionWithTrailingNewlines)):
(TEST(WritingTools, CompositionWithTrailingBreaks)):
(TEST(WritingTools, ContextRangeWithNoSelection)):
(TEST(WritingTools, ContextRangeFromCaretSelection)):
(TEST(WritingTools, ContextRangeFromRangeSelection)):

Canonical link: https://commits.webkit.org/283725@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list