Skip to content

Commit

Permalink
Bug 1840856: Fixed linefeed/linebreak issues for contenteditable. r=m…
Browse files Browse the repository at this point in the history
…asayuki,dom-core

This patch is related to Bug 1840822, which fixes some issues
regarding additional invisible linebreaks needed at the end of
contenteditables.
This patch in particular fixes the case where the user
presses enter at the end of a pre-formatted
contenteditable, e.g.:
```
<span contenteditable style="display:block;white-space:pre-line">[]</span>
```
Prior to this patch, only one `<br>` was added,
the invisible padding linebreak was missing.
With this patch applied, the behaviour should be as expected:
```
<span contenteditable style="display:block;white-space:pre-line">\n<br></span>
```

Differential Revision: https://phabricator.services.mozilla.com/D190217
  • Loading branch information
jnjaeschke committed Oct 10, 2023
1 parent 13ff99f commit 5005fe0
Show file tree
Hide file tree
Showing 5 changed files with 631 additions and 1,380 deletions.
5 changes: 3 additions & 2 deletions editor/libeditor/HTMLEditSubActionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1871,8 +1871,9 @@ HTMLEditor::InsertParagraphSeparatorAsSubAction(const Element& aEditingHost) {
return aDefaultParagraphSeparator == ParagraphSeparator::br ||
!HTMLEditUtils::CanElementContainParagraph(
*aEditableBlockElement) ||
HTMLEditUtils::ShouldInsertLinefeedCharacter(
aCandidatePointToSplit, aEditingHost);
(HTMLEditUtils::ShouldInsertLinefeedCharacter(
aCandidatePointToSplit, aEditingHost) &&
HTMLEditUtils::IsDisplayOutsideInline(aEditingHost));
}

// If the nearest block parent is a single-line container declared in
Expand Down
4 changes: 1 addition & 3 deletions editor/libeditor/HTMLEditUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,9 @@ bool HTMLEditUtils::ShouldInsertLinefeedCharacter(
BlockInlineCheck::UseComputedDisplayOutsideStyle);

// If and only if the nearest block is the editing host or its parent,
// and the outer display value of the editing host is inline, and new
// line character is preformatted, we should insert a linefeed.
// and new line character is preformatted, we should insert a linefeed.
return (!closestEditableBlockElement ||
closestEditableBlockElement == &aEditingHost) &&
HTMLEditUtils::IsDisplayOutsideInline(aEditingHost) &&
EditorUtils::IsNewLinePreformatted(
*aPointToInsert.ContainerAs<nsIContent>());
}
Expand Down
Loading

0 comments on commit 5005fe0

Please sign in to comment.