Changeset 249307 in webkit


Ignore:
Timestamp:
Aug 29, 2019 6:40:58 PM (5 years ago)
Author:
timothy@apple.com
Message:

Copying and pasting two paragraphs with a newline between them results in stray paragraph with newline inside.
https://bugs.webkit.org/show_bug.cgi?id=201306

Reviewed by Wenson Hsieh.

Source/WebCore:

Test: editing/pasteboard/paste-without-nesting.html

  • editing/ReplaceSelectionCommand.cpp:

(WebCore::ReplaceSelectionCommand::moveNodeOutOfAncestor): Consider the ancestor node safe to remove
if there is no rendered text inside, not just if there are any child nodes.

LayoutTests:

  • editing/pasteboard/paste-without-nesting-expected.txt: Updated results.
  • editing/pasteboard/paste-without-nesting.html: Added new test case.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249305 r249307  
     12019-08-29  Timothy Hatcher  <timothy@apple.com>
     2
     3        Copying and pasting two paragraphs with a newline between them results in stray paragraph with newline inside.
     4        https://bugs.webkit.org/show_bug.cgi?id=201306
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * editing/pasteboard/paste-without-nesting-expected.txt: Updated results.
     9        * editing/pasteboard/paste-without-nesting.html: Added new test case.
     10
    1112019-08-29  Devin Rousso  <drousso@apple.com>
    212
  • trunk/LayoutTests/editing/pasteboard/paste-without-nesting-expected.txt

    r101629 r249307  
    77PASS confirmedMarkup is '<div><b><i>Hello</i></b></div><div><b><i>world</i></b></div>'
    88PASS confirmedMarkup is '<div style="text-align: center;"><div><font color="#ff0000"><b><i>hello</i></b></font></div><div><font color="#ff0000"><b><i>world</i></b></font></div></div>'
     9PASS confirmedMarkup is '<p>Line One</p><p>Line Two</p>'
    910PASS successfullyParsed is true
    1011
  • trunk/LayoutTests/editing/pasteboard/paste-without-nesting.html

    r155276 r249307  
    4141testCopyPaste("div", "<div><b><i>Hello</i></b></div><div><b><i>world</i></b></div>", "<div><b><i>Hello</i></b></div><div><b><i>world</i></b></div>");
    4242testCopyPaste("div", "<div style=\"text-align: center;\"><div><font color=\"#ff0000\"><b><i>hello</i></b></font></div><div><font color=\"#ff0000\"><b><i>world</i></b></font></div></div>", "<div style=\"text-align: center;\"><div><font color=\"#ff0000\"><b><i>hello</i></b></font></div><div><font color=\"#ff0000\"><b><i>world</i></b></font></div></div>");
     43testCopyPaste("div", "<p>Line One</p>&#10;<p>Line Two</p>", "<p>Line One</p><p>Line Two</p>");
    4344
    4445root.style.display = "none";
  • trunk/Source/WebCore/ChangeLog

    r249305 r249307  
     12019-08-29  Timothy Hatcher  <timothy@apple.com>
     2
     3        Copying and pasting two paragraphs with a newline between them results in stray paragraph with newline inside.
     4        https://bugs.webkit.org/show_bug.cgi?id=201306
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Test: editing/pasteboard/paste-without-nesting.html
     9
     10        * editing/ReplaceSelectionCommand.cpp:
     11        (WebCore::ReplaceSelectionCommand::moveNodeOutOfAncestor): Consider the ancestor node safe to remove
     12        if there is no rendered text inside, not just if there are any child nodes.
     13
    1142019-08-29  Devin Rousso  <drousso@apple.com>
    215
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r248846 r249307  
    705705}
    706706
     707static inline bool hasRenderedText(const Text& text)
     708{
     709    return text.renderer() && text.renderer()->hasRenderedText();
     710}
     711
    707712void ReplaceSelectionCommand::moveNodeOutOfAncestor(Node& node, Node& ancestor, InsertedNodes& insertedNodes)
    708713{
     
    723728        insertNodeBefore(WTFMove(protectedNode), *nodeToSplitTo);
    724729    }
    725     if (!ancestor.firstChild()) {
     730
     731    document().updateLayoutIgnorePendingStylesheets();
     732
     733    bool safeToRemoveAncestor = true;
     734    for (auto* child = ancestor.firstChild(); child; child = child->nextSibling()) {
     735        if (is<Text>(child) && hasRenderedText(downcast<Text>(*child))) {
     736            safeToRemoveAncestor = false;
     737            break;
     738        }
     739
     740        if (is<Element>(child)) {
     741            safeToRemoveAncestor = false;
     742            break;
     743        }
     744    }
     745
     746    if (safeToRemoveAncestor) {
    726747        insertedNodes.willRemoveNode(&ancestor);
    727748        removeNode(ancestor);
    728749    }
    729 }
    730 
    731 static inline bool hasRenderedText(const Text& text)
    732 {
    733     return text.renderer() && text.renderer()->hasRenderedText();
    734750}
    735751
Note: See TracChangeset for help on using the changeset viewer.