Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Replace paragraphs with line breaks in message output #834

Merged
merged 28 commits into from
Oct 18, 2023

Conversation

jonnyandrew
Copy link
Contributor

@jonnyandrew jonnyandrew commented Oct 2, 2023

@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (450db53) 88.08% compared to head (ba2e8c9) 88.29%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #834      +/-   ##
============================================
+ Coverage     88.08%   88.29%   +0.20%     
============================================
  Files           161      114      -47     
  Lines         18167    16722    -1445     
  Branches        971      631     -340     
============================================
- Hits          16003    14764    -1239     
- Misses         1908     1929      +21     
+ Partials        256       29     -227     
Flag Coverage Δ
uitests ?
uitests-android ?
uitests-ios ?
unittests 88.29% <98.60%> (+1.93%) ⬆️
unittests-android ?
unittests-ios 76.91% <ø> (+0.23%) ⬆️
unittests-rust 89.46% <98.60%> (-0.46%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
crates/wysiwyg/src/composer_model/delete_text.rs 97.42% <100.00%> (+0.01%) ⬆️
...rates/wysiwyg/src/composer_model/example_format.rs 97.31% <100.00%> (-0.16%) ⬇️
...s/wysiwyg/src/composer_model/format_inline_code.rs 90.61% <100.00%> (-8.08%) ⬇️
crates/wysiwyg/src/composer_model/quotes.rs 97.30% <100.00%> (ø)
crates/wysiwyg/src/dom/dom_block_nodes.rs 98.03% <100.00%> (+0.02%) ⬆️
crates/wysiwyg/src/dom/dom_list_methods.rs 95.52% <100.00%> (-2.40%) ⬇️
crates/wysiwyg/src/dom/dom_struct.rs 91.24% <100.00%> (ø)
crates/wysiwyg/src/dom/find_extended_range.rs 99.31% <100.00%> (-0.69%) ⬇️
crates/wysiwyg/src/dom/iter.rs 87.68% <100.00%> (-0.27%) ⬇️
crates/wysiwyg/src/dom/nodes/dom_node.rs 88.15% <100.00%> (-0.66%) ⬇️
... and 7 more

... and 61 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonnyandrew jonnyandrew force-pushed the jonny/paragraph-to-line-break branch 2 times, most recently from a9b654a to d0a6ad8 Compare October 4, 2023 16:20
@jonnyandrew jonnyandrew changed the title POC: Replace paragraphs with line breaks in message output Replace paragraphs with line breaks in message output Oct 4, 2023
@jonnyandrew jonnyandrew requested a review from a team October 4, 2023 16:31
@jonnyandrew jonnyandrew marked this pull request as ready for review October 4, 2023 16:31
Copy link
Contributor

@langleyd langleyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have all the context but the premise makes sense, and intuitively approach taken with the implementation makes sense to me and seems like a good direction to bring things. Just a couple of clarifications.

We should probably merge #842 first or we may see even more paragraphs in the message content, maybe we can merge it in to re-run tests.

_ => ComposerUpdate::keep(),
}
}
DomNode::Container(_) | DomNode::LineBreak(_) => match start_type {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we convert paragraphs to line breaks do we still need LineBreak type internally in the Dom?

Copy link
Contributor Author

@jonnyandrew jonnyandrew Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function to add line breaks is deprecated and fell out of use at the point of doing #472 I believe, so the Dom shouldn't contain these nodes. However, the LineBreak node is still being used to represent line breaks in the Dom immediately after parsing, before being post-processed into paragraphs.

This is a bit problematic because although we can expect that the Dom should no longer contain LineBreaks, there is a lot of existing code that expects that it might which is effectively dead code and a maintenance burden.

Perhaps we can either

  1. Remove the LineBreak node and parse <br> directly to Container. It will be the most effort but, after this PR, we have compatible tests to make this easier. There is also the question of whether this would put too much logic in the HTML parser.
  2. Keep the LineBreak node but refactor it to something like Placeholder(LineBreak), adding an invariant assertion that it should not exist in the Dom. We could remove any logic that handles this node type and replace it with an unreachable! error.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that. I'm ok with either option, was more trying to understand it's current use.

Copy link
Contributor Author

@jonnyandrew jonnyandrew Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dom
}

// Group consecutive inline nodes into paragraphs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe a bit the needs to group consecutive inline nodes into paragraphs?

Is it that we are removing the linebreak type and adding the requirement of inline items to be grouped in a paragraphs, to simplify the implementation and assumptions we can make?

@langleyd
Copy link
Contributor

It's a snapshot test that's failing and I downloaded both files, they both look the same(used an online tool to compare) and I can't see any pixels that change but the content is different. So I think we can just accept the new one.

- Reverting snapshot as I think the latest difference might be because of running locally on my machine(maybe as it's intel chip).
- Check if changing input to <br/>'s fixes it.
Copy link
Contributor

@aringenbach aringenbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works on my Mac for this test (if using iOS < 17.0).

Also it's needed to update the other block quote test that way to preserve functional snapshot tests:

    func testMultipleBlocksContent() throws {
        viewModel.setHtmlContent(
            """
            <blockquote>Some<br/>\
            multi-line<br/>\
            quote</blockquote>\
            <br/>\
            <br/>\
            Some text<br/>\
            <br/>\
            <pre>A\n\tcode\nblock</pre>\
            <br/>\
            <br/>\
            Some <code>inline</code> code
            """
        )
        assertSnapshot(
            matching: hostingController,
            as: .image(on: .iPhone13),
            record: isRecord
        )

@jonnyandrew
Copy link
Contributor Author

@langleyd is there any change still needed on iOS to fix the test failures? And about #834 (comment), am I ok to open a separate issue?

@sonarcloud
Copy link

sonarcloud bot commented Oct 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jonnyandrew jonnyandrew merged commit 0663938 into main Oct 18, 2023
8 checks passed
@jonnyandrew jonnyandrew deleted the jonny/paragraph-to-line-break branch October 18, 2023 10:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants