Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 405782ff2e808caa3d518d03fc5de7b15de8098b
      
https://github.com/WebKit/WebKit/commit/405782ff2e808caa3d518d03fc5de7b15de8098b
  Author: Richard Robinson <[email protected]>
  Date:   2024-06-27 (Thu, 27 Jun 2024)

  Changed paths:
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/editing/Editor.cpp
    M Source/WebCore/editing/VisibleUnits.cpp
    M Source/WebCore/editing/VisibleUnits.h
    A Source/WebCore/editing/WritingToolsCompositionCommand.cpp
    A Source/WebCore/editing/WritingToolsCompositionCommand.h
    M Source/WebCore/page/Page.cpp
    M Source/WebCore/page/Page.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] Tapping on Restart after a Magic Rewrite duplicates the 
sentence
https://bugs.webkit.org/show_bug.cgi?id=275818
rdar://130065512

Reviewed by Aditya Keerthi.

In the existing implementation of Rewrite/Composition, there were two 
fundamental issues:

* The stateful context range must always be up-to-date, which was a fragile 
architecture as it relied
upon it being updated with every different type of replacement operation.

* While undo/redo happened to work for trivial cases, the 
WritingToolsController was not aware of these
changes happening, which would also put the context range out of date. 
Additionally, each individual ReplaceSelectionCommand
was being undone or redone at a time, instead of the entire set of constituent 
commands belong to a particular composition.

To fix this, introduce a new specialized type of edit command specifically 
designed for rewrites and compositions,
and have it encapsulate both a group of ReplaceSelectionCommands as well as its 
corresponding context range.
This facilitates the ability to undo/redo a group of commands at once, and also 
ensures that the context range is always correct
for a given command.

To ensure that the right command is always being used, an undo and redo stack 
are now used to store the commands,
and a given command moves from one stack to the other when it is undone or 
redone. This also allows the "show original"
and "show rewritten" commands to function by simply undo-ing or redo-ing all 
the commands.

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/editing/Editor.cpp:
(WebCore::Editor::unappliedEditing):
(WebCore::Editor::reappliedEditing):
* Source/WebCore/editing/VisibleUnits.cpp:
(WebCore::rangeExpandedAroundRangeByCharacters):
* Source/WebCore/editing/VisibleUnits.h:
* Source/WebCore/editing/WritingToolsCompositionCommand.cpp: Added.
(WebCore::WritingToolsCompositionCommand::WritingToolsCompositionCommand):
(WebCore::WritingToolsCompositionCommand::replaceFragment):
(WebCore::WritingToolsCompositionCommand::doApply):
* Source/WebCore/editing/WritingToolsCompositionCommand.h: Added.
(WebCore::WritingToolsCompositionCommand::create):
(WebCore::WritingToolsCompositionCommand::endingContextRange const):
* Source/WebCore/page/Page.cpp:
(WebCore::Page::respondToUnappliedWritingToolsEditing):
(WebCore::Page::respondToReappliedWritingToolsEditing):
* Source/WebCore/page/Page.h:
* Source/WebCore/page/writing-tools/WritingToolsController.h:
* Source/WebCore/page/writing-tools/WritingToolsController.mm:
(WebCore::WritingToolsController::WritingToolsController):
(WebCore::WritingToolsController::willBeginWritingToolsSession):
(WebCore::WritingToolsController::compositionSessionDidReceiveTextWithReplacementRange):
(WebCore::WritingToolsController::writingToolsSessionDidReceiveAction<WritingTools::Session::Type::Composition>):
(WebCore::WritingToolsController::respondToUnappliedEditing):
(WebCore::WritingToolsController::respondToReappliedEditing):
(WebCore::WritingToolsController::contextRangeForSessionWithID const):
(WebCore::WritingToolsController::replaceContentsOfRangeInSession):
(WebCore::WritingToolsController::replaceContentsOfRangeInSessionInternal): 
Deleted.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingTools.mm:
(TEST(WritingTools, CompositionWithUndo)):
(TEST(WritingTools, CompositionWithMultipleUndosAndRestarts)):
(TEST(WritingTools, CompositionWithUndoAndRestart)):
(TEST(WritingTools, Composition)):
(TEST(WritingTools, CompositionRevert)):
(TEST(WritingTools, CompositionWithMultipleChunks)):
(TEST(WritingTools, ContextRangeFromCaretSelection)):
(TEST(WritingTools, ContextRangeFromRangeSelection)):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to