Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 90bbdbb17a629ae973babc361cf167577eff0668
      
https://github.com/WebKit/WebKit/commit/90bbdbb17a629ae973babc361cf167577eff0668
  Author: Richard Robinson <richard_robins...@apple.com>
  Date:   2024-05-20 (Mon, 20 May 2024)

  Changed paths:
    M Source/WebCore/editing/TextIterator.cpp
    M Source/WebCore/editing/TextIteratorBehavior.h
    M Source/WebCore/editing/cocoa/AttributedString.mm
    M Source/WebCore/editing/cocoa/HTMLConverter.mm
    M Source/WebKit/WebProcess/WebPage/Cocoa/UnifiedTextReplacementController.mm
    M Source/WebKit/WebProcess/WebPage/UnifiedTextReplacementController.h

  Log Message:
  -----------
  [Unified Text Replacement] `willBeginTextReplacementSession` sometimes does 
not return a context if the text lengths differ
https://bugs.webkit.org/show_bug.cgi?id=274325
rdar://128285414

Reviewed by Aditya Keerthi.

The length of the string produced by `editingAttributedString` and the 
character count produced by
`TextIterator` can sometimes differ. This can happen when there are images in 
the HTML, as `editingAttributedString`
handles them in a special case.

Fix by adding a new `TextIteratorBehavior` option that acts the same as 
`EmitsObjectReplacementCharacters`,
but only for images, and then use this behavior anywhere in 
UnifiedTextReplacementController that
needs character ranges or counts.

Also fix a few issues with attachments in attributed strings:

* When converting an `AttributedString` to an `NSAttributedString` with an 
attachment, if the attachment
does not have a "preferred" filename, an empty file wrapper will be created. 
Fix by always creating a file
wrapper.

* When converting HTML with an image to an attributed string, the position of 
the resulting attachment in
the produced attributed string is sometimes incorrect. This is because the 
length of the attachment itself
is never taken into account, and so consequent parts of the string will be 
inserted in too early of a position.
Fix by accounting for the length of the attachment.

* Source/WebCore/editing/TextIterator.cpp:
(WebCore::TextIterator::TextIterator):
(WebCore::TextIterator::handleReplacedElement):
* Source/WebCore/editing/TextIteratorBehavior.h:
* Source/WebCore/editing/cocoa/AttributedString.mm:
(WebCore::toNSObject):
* Source/WebCore/editing/cocoa/HTMLConverter.mm:
(WebCore::editingAttributedString):
* Source/WebKit/WebProcess/WebPage/Cocoa/UnifiedTextReplacementController.mm:
(WebKit::UnifiedTextReplacementController::characterRange):
(WebKit::UnifiedTextReplacementController::characterCount):
(WebKit::UnifiedTextReplacementController::resolveCharacterRange):
(WebKit::UnifiedTextReplacementController::plainText):
(WebKit::UnifiedTextReplacementController::willBeginTextReplacementSession):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveReplacements):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveTextWithReplacementRange):
(WebKit::UnifiedTextReplacementController::textReplacementSessionPerformEditActionForPlainText):
(WebKit::UnifiedTextReplacementController::contextRangeForSessionOrRangeWithUUID
 const):
(WebKit::UnifiedTextReplacementController::replaceContentsOfRangeInSessionInternal):
* Source/WebKit/WebProcess/WebPage/UnifiedTextReplacementController.h:

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



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

Reply via email to