Skip to content

Commit

Permalink
Simplify TypingCommand::makeEditableRootEmpty() by removing firstElem…
Browse files Browse the repository at this point in the history
…entChild

Simplify TypingCommand::makeEditableRootEmpty() by removing firstElementChild
https://bugs.webkit.org/show_bug.cgi?id=248191

Reviewed by Ryosuke Niwa.

Merge - https://src.chromium.org/viewvc/blink?view=revision&revision=180673

Simplify TypingCommand::makeEditableRootEmpty() a bit by avoiding an unnecessary
call to firstElementChild.

In this if scope, we already know that the root node has a single child.
Therefore, there is no reason to do a tree traversal, we can directly call
ContainerNode::firstChild().

firstElementChild never explores descendants and only looks
for the first direct child that is an Element. In this case, we don't need to
check if the child is an Element as we can pass a Node to hasTagName(brTag).

* Source/WebCore/editing/TypingCommand.cpp:
(TypingCommand::makeEditableRootEmpty): Simplify by removing references to firstElementChild

Canonical link: https://commits.webkit.org/256950@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Nov 22, 2022
1 parent 0987e57 commit b78015a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Source/WebCore/editing/TypingCommand.cpp
Expand Up @@ -617,7 +617,7 @@ bool TypingCommand::makeEditableRootEmpty()
if (!root || !root->firstChild())
return false;

if (root->firstChild() == root->lastChild() && root->firstElementChild() && root->firstElementChild()->hasTagName(brTag)) {
if (root->firstChild() == root->lastChild() && root->firstChild()->hasTagName(brTag)) {
// If there is a single child and it could be a placeholder, leave it alone.
if (root->renderer() && root->renderer()->isRenderBlockFlow())
return false;
Expand Down

0 comments on commit b78015a

Please sign in to comment.