LibWeb: Insert newlines between block-level elements when copying text#8905
Open
officialasishkumar wants to merge 1 commit intoLadybirdBrowser:masterfrom
Open
Conversation
Collaborator
|
Hello! One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the |
45d680d to
b713a4e
Compare
Contributor
|
@officialasishkumar Please slow down. Opening 10 PRs in a row as a new contributor is too much. Open just one, learn the ropes and contributing guidelines, and go from there. |
The visible_text_in_range() helper used for clipboard serialisation only iterated over Text nodes, ignoring the block-level element boundaries between them. Selecting text that spans multiple <div> (or other block) elements would therefore produce a result with all the text concatenated without any separating newlines. Fix by also processing Element nodes while iterating the range: if an element's layout node is a block container or a line-break node (<br>), and the output buffer already contains some text, append a newline before continuing. This matches the plain-text serialisation behaviour of other browsers for the common case. Fixes LadybirdBrowser#7315.
b713a4e to
1eaecaa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When copying text that spans multiple block-level elements (e.g. adjacent
<div>nodes), the clipboard received all the text concatenated withoutany newlines between the elements.
The root cause was in
visible_text_in_range(), which iterated theselection range and only appended data from
Textnodes. Element nodes(including block containers and
<br>) were silently skipped, so noline separators were ever inserted.
Fix: extend the iteration callback to also check element nodes: if
the node's layout representation is a block container (
<div>,<p>,<h1>–<h6>, etc.) or aBreakNode(<br>), and the output bufferis non-empty, a newline is inserted. The non-empty guard prevents a
spurious leading newline at the start of the copied text.
This matches the plain-text clipboard serialisation behaviour of
Chrome and Firefox for the common case.
Fixes #7315.