-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Unified Text Replacement] willBeginTextReplacementSession
sometimes does not return a context if the text lengths differ
#28722
Conversation
EWS run on previous version of this PR (hash 1d99dd6) |
Source/WebKit/WebProcess/WebPage/Cocoa/UnifiedTextReplacementController.mm
Outdated
Show resolved
Hide resolved
EWS run on previous version of this PR (hash d747836) |
Source/WebKit/WebProcess/WebPage/Cocoa/UnifiedTextReplacementController.mm
Show resolved
Hide resolved
EWS run on previous version of this PR (hash 30a4f24) |
EWS run on previous version of this PR (hash 4729c5e) |
[fileWrapper setPreferredFilename:filenameByFixingIllegalCharacters((NSString *)value.preferredFilename)]; | ||
} | ||
|
||
auto textAttachment = adoptNS([[PlatformNSTextAttachment alloc] initWithFileWrapper:fileWrapper.get()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intentionally added newlines for readability
if (RefPtr imageElement = dynamicDowncast<HTMLImageElement>(node); imageElement && includeImages == IncludeImages::Yes) { | ||
RetainPtr attachmentAttributedString = attributedStringWithAttachmentForElement(*imageElement); | ||
[string appendAttributedString:attachmentAttributedString.get()]; | ||
stringLength += [attachmentAttributedString length]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this compatible with:
auto currentTextLength = it.text().length();
and
[string setAttributes:attrs.get() range:NSMakeRange(stringLength, currentTextLength)];
below,
given that TextIterator it(range)
does not have any additional behaviors specified?
Wouldn't it result in length mismatches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it wasn't compatible before, but is now. This change doesn't actually affect the string lengths, just changes the position of where the text that comes after the attachment goes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(My tests also exercise this thoroughly)
EWS run on current version of this PR (hash 5c4632a) |
β¦s 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
5c4632a
to
90bbdbb
Compare
Committed 279002@main (90bbdbb): https://commits.webkit.org/279002@main Reviewed commits have been landed. Closing PR #28722 and removing active labels. |
90bbdbb
5c4632a