Skip to content
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] Replacements should maintain the original text attributes #25564

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

rr-codes
Copy link
Contributor

@rr-codes rr-codes commented Mar 7, 2024

6cffe2c

[Unified Text Replacement] Replacements should maintain the original text attributes
https://bugs.webkit.org/show_bug.cgi?id=270606
rdar://122835651

Reviewed by Wenson Hsieh.

Add support for attributed strings to work properly and have their attributes persisted.

Also, add `WEBCORE_EXPORT` to `showTreeForThis` to ease future debugging, and make a correctness
fix for an unrelated API test.

* Source/WebCore/dom/Node.h:
* Source/WebCore/editing/WebContentReader.h:
* Source/WebCore/editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::replaceSelectionWithAttributedString):
* Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragment):
(WebCore::WebContentReader::readRTFD):
(WebCore::WebContentMarkupReader::readRTFD):
(WebCore::WebContentReader::readRTF):
(WebCore::WebContentMarkupReader::readRTF):
(WebCore::createFragmentAndAddResources): Deleted.
* Source/WebKit/Sources.txt:
* Source/WebKit/SourcesCocoa.txt:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/WebPage/Cocoa/UnifiedTextReplacementController.mm: Renamed from Source/WebKit/WebProcess/WebPage/UnifiedTextReplacementController.cpp.
(WebKit::replaceTextInRange):
(WebKit::replaceContentsInRange):
(WebKit::extendedBoundaryPoint):
(WebKit::findReplacementMarkerByUUID):
(WebKit::UnifiedTextReplacementController::UnifiedTextReplacementController):
(WebKit::UnifiedTextReplacementController::willBeginTextReplacementSession):
(WebKit::UnifiedTextReplacementController::didBeginTextReplacementSession):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveReplacements):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidUpdateStateForReplacement):
(WebKit::UnifiedTextReplacementController::didEndTextReplacementSession):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveTextWithReplacementRange):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveEditAction):
* Source/WebKit/WebProcess/WebPage/UnifiedTextReplacementController.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyRTF.mm:
(checkColor):

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

ba0c4ae

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt   πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-skia
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2   πŸ§ͺ gtk-wk2
  πŸ›  tv-sim   πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
  πŸ›  watch-sim

@rr-codes rr-codes self-assigned this Mar 7, 2024
@rr-codes rr-codes added the HTML Editing For bugs in HTML editing support (including designMode and contentEditable). label Mar 7, 2024
Source/WebCore/dom/Node.h Show resolved Hide resolved
EXPECT_EQ(green, observedRed);
EXPECT_EQ(green, observedGreen);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just working before because the tested red and green values were always equal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup lol


auto newResolvedRange = resolveCharacterRange(*sessionRange, newRange);
RELEASE_ASSERT(sessionRangeCharacterCount >= range.location + range.length);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this release assert ok to leave in? It's needed because otherwise there would be an underflow in the below lines if this was somehow ever false. I could do an early return with a debug assert too, but this should never ever happen in the first place.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A RELEASE_ASSERT is not the answer here, unless there is some security implication. Otherwise, why are we creating an even worse user experience because of a bug in our code?


replaceTextInRange(*frame, newResolvedRange, newText);
if (UNLIKELY(sessionRangeCharacterCount < range.location + range.length)) {
RELEASE_LOG(UnifiedTextReplacement, "UnifiedTextReplacementController::textReplacementSessionDidReceiveTextWithReplacementRange (%s) => trying to replace a range larger than the context range (context range count: %llu, range.location %llu, range.length %llu)", uuid.toString().utf8().data(), sessionRangeCharacterCount, range.location, range.length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - RELEASE_LOG_ERROR?

case WebKit::WebTextReplacementData::EditAction::UndoAll: {
auto updatedContents = updatedLiveRange->cloneContents();
if (updatedContents.hasException()) {
RELEASE_LOG(UnifiedTextReplacement, "UnifiedTextReplacementController::textReplacementSessionDidReceiveEditAction (%s) => exception when cloning contents after action", uuid.toString().utf8().data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@rr-codes rr-codes added the merge-queue Applied to send a pull request to merge-queue label Mar 8, 2024
…text attributes

https://bugs.webkit.org/show_bug.cgi?id=270606
rdar://122835651

Reviewed by Wenson Hsieh.

Add support for attributed strings to work properly and have their attributes persisted.

Also, add `WEBCORE_EXPORT` to `showTreeForThis` to ease future debugging, and make a correctness
fix for an unrelated API test.

* Source/WebCore/dom/Node.h:
* Source/WebCore/editing/WebContentReader.h:
* Source/WebCore/editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::replaceSelectionWithAttributedString):
* Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragment):
(WebCore::WebContentReader::readRTFD):
(WebCore::WebContentMarkupReader::readRTFD):
(WebCore::WebContentReader::readRTF):
(WebCore::WebContentMarkupReader::readRTF):
(WebCore::createFragmentAndAddResources): Deleted.
* Source/WebKit/Sources.txt:
* Source/WebKit/SourcesCocoa.txt:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/WebPage/Cocoa/UnifiedTextReplacementController.mm: Renamed from Source/WebKit/WebProcess/WebPage/UnifiedTextReplacementController.cpp.
(WebKit::replaceTextInRange):
(WebKit::replaceContentsInRange):
(WebKit::extendedBoundaryPoint):
(WebKit::findReplacementMarkerByUUID):
(WebKit::UnifiedTextReplacementController::UnifiedTextReplacementController):
(WebKit::UnifiedTextReplacementController::willBeginTextReplacementSession):
(WebKit::UnifiedTextReplacementController::didBeginTextReplacementSession):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveReplacements):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidUpdateStateForReplacement):
(WebKit::UnifiedTextReplacementController::didEndTextReplacementSession):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveTextWithReplacementRange):
(WebKit::UnifiedTextReplacementController::textReplacementSessionDidReceiveEditAction):
* Source/WebKit/WebProcess/WebPage/UnifiedTextReplacementController.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyRTF.mm:
(checkColor):

Canonical link: https://commits.webkit.org/275821@main
@webkit-commit-queue
Copy link
Collaborator

Committed 275821@main (6cffe2c): https://commits.webkit.org/275821@main

Reviewed commits have been landed. Closing PR #25564 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 6cffe2c into WebKit:main Mar 8, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HTML Editing For bugs in HTML editing support (including designMode and contentEditable).
Projects
None yet
5 participants