⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 266075 in webkit


Ignore:
Timestamp:
Aug 24, 2020, 11:06:01 AM (6 years ago)
Author:
sihui_liu@apple.com
Message:

Source/WebCore:
Text manipulation should not manipulate nodes out of paragraph range
https://bugs.webkit.org/show_bug.cgi?id=215406

Reviewed by Wenson Hsieh.

TextManipulationController currently does not set correct start path for insertion. Therefore, it does not mark
the nodes on the start path but out of range correctly, and may change position of those nodes by mistake. For
example, in the newly added test, text node "zero" can be moved around even though it is not in range.

API test: TextManipulation.CompleteTextManipulationShouldOnlyChangeNodesInParagraphRange

  • editing/TextManipulationController.cpp:

(WebCore::TextManipulationController::replace):

Tools:
Text manipulationshould not manipulate nodes out of paragraph range
https://bugs.webkit.org/show_bug.cgi?id=215406

Reviewed by Wenson Hsieh.

  • TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:

(TestWebKitAPI::TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r266074 r266075  
     12020-08-24  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Text manipulation should not manipulate nodes out of paragraph range
     4        https://bugs.webkit.org/show_bug.cgi?id=215406
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        TextManipulationController currently does not set correct start path for insertion. Therefore, it does not mark
     9        the nodes on the start path but out of range correctly, and may change position of those nodes by mistake. For
     10        example, in the newly added test, text node "zero" can be moved around even though it is not in range.
     11
     12        API test: TextManipulation.CompleteTextManipulationShouldOnlyChangeNodesInParagraphRange
     13
     14        * editing/TextManipulationController.cpp:
     15        (WebCore::TextManipulationController::replace):
     16
    1172020-08-24  Devin Rousso  <drousso@apple.com>
    218
  • trunk/Source/WebCore/editing/TextManipulationController.cpp

    r265561 r266075  
    830830
    831831    HashSet<Ref<Node>> reusedOriginalNodes;
    832     Vector<NodeEntry> lastTopDownPath;
    833832    Vector<NodeInsertion> insertions;
     833    auto startTopDownPath = getPath(commonAncestor.get(), firstContentNode.get());
     834    while (!startTopDownPath.isEmpty()) {
     835        auto lastNode = startTopDownPath.last();
     836        ASSERT(is<ContainerNode>(lastNode.get()));
     837        if (!downcast<ContainerNode>(lastNode.get()).hasOneChild())
     838            break;
     839        nodesToRemove.add(startTopDownPath.takeLast());
     840    }
     841    auto lastTopDownPath = startTopDownPath.map([&](auto node) -> NodeEntry {
     842        reusedOriginalNodes.add(node.copyRef());
     843        return { node, node };
     844    });
     845
    834846    for (size_t index = 0; index < replacementTokens.size(); ++index) {
    835847        auto& replacementToken = replacementTokens[index];
  • trunk/Tools/ChangeLog

    r266063 r266075  
     12020-08-24  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Text manipulationshould not manipulate nodes out of paragraph range
     4        https://bugs.webkit.org/show_bug.cgi?id=215406
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
     9        (TestWebKitAPI::TEST):
     10
    1112020-08-24  Aditya Keerthi  <akeerthi@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm

    r265561 r266075  
    31323132}
    31333133
     3134TEST(TextManipulation, CompleteTextManipulationShouldOnlyChangeNodesInParagraphRange)
     3135{
     3136    auto delegate = adoptNS([[TextManipulationDelegate alloc] init]);
     3137    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
     3138    [webView _setTextManipulationDelegate:delegate.get()];
     3139    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html>"
     3140        "<head>"
     3141            "<style>"
     3142                "span { white-space:pre; }"
     3143            "</style>"
     3144        "</head>"
     3145        "<body>"
     3146            "<span>zero &#10;<b>two four</b></span>"
     3147            "one"
     3148            "<i>three</i>"
     3149        "</body>"];
     3150
     3151    done = false;
     3152    [webView _startTextManipulationsWithConfiguration:nil completion:^{
     3153        done = true;
     3154    }];
     3155    TestWebKitAPI::Util::run(&done);
     3156
     3157    auto *items = [delegate items];
     3158    EXPECT_EQ(items.count, 2UL);
     3159    EXPECT_EQ(items[0].tokens.count, 2UL);
     3160    EXPECT_WK_STREQ("zero", items[0].tokens[0].content);
     3161    EXPECT_WK_STREQ(" \n", items[0].tokens[1].content);
     3162    EXPECT_EQ(items[1].tokens.count, 3UL);
     3163    EXPECT_WK_STREQ("two four", items[1].tokens[0].content);
     3164    EXPECT_WK_STREQ("one", items[1].tokens[1].content);
     3165    EXPECT_WK_STREQ("three", items[1].tokens[2].content);
     3166
     3167    done = false;
     3168    [webView _completeTextManipulationForItems:@[(_WKTextManipulationItem *)createItem(items[1].identifier, {
     3169        { items[1].tokens[1].identifier, @"one" },
     3170        { items[1].tokens[0].identifier, @"two" },
     3171        { items[1].tokens[2].identifier, @"three" },
     3172        { items[1].tokens[0].identifier, @"four" }
     3173    }).get()] completion:^(NSArray<NSError *> *errors) {
     3174        EXPECT_EQ(errors, nil);
     3175        done = true;
     3176    }];
     3177    TestWebKitAPI::Util::run(&done);
     3178    EXPECT_WK_STREQ("<span>zero \n</span>one<span><b>two</b></span><i>three</i><span><b>four</b></span>",
     3179        [webView stringByEvaluatingJavaScript:@"document.body.innerHTML"]);
     3180}
     3181
    31343182TEST(TextManipulation, TextManipulationTokenDebugDescription)
    31353183{
Note: See TracChangeset for help on using the changeset viewer.