basecamp / basecamp/trix

Inserting Content Attachment deletes existing <br> tag

Open
#837 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
20k
Forks
1.1k
Avg merge
3d 12h
Merged PRs (30d)
13

Description

I'm starting with a Trix editor with two text lines, a blank line and a heading:

```html


Test

Test




Test


```

It renders correctly like this:

image

I am then implementing the 'horizontal rule' approach (as described in [this comment](https://github.com/basecamp/trix/issues/570#issuecomment-440436960) from @javan a couple of years ago).

I've noticed that if I insert such a content attachment in the blank space, one of the `
` tags is deleted from the DOM - there is now only one after the second `Test`:

```html


Test

Test







```

I'm not entirely sure why this is (I've attempted to look at the Trix code but I'm very unfamiliar with it) but it's causing me an issue further down the line (I won't go into my use case here, unless you want me to). Is it possible for someone to explain why this is happening and where in the code it's doing it?

Interestingly, if the content attachment is deleted, the missing `
` returns!

This fiddle allows you to see the issue in action (you need to inspect the HTML of the Trix editor before and after to see it): https://codepen.io/codepatterns/pen/YzqoKqY.

I would expect the insertion of the content attachment not to remove the `
` tag as it has been typed in on purpose.

Thanks! 🙏

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue in the linked CodePen using the HTML shown in the report, then inspect the editor DOM before and after inserting and deleting the content attachment. Trace the content-attachment insertion path to identify why the blank-line
is removed. Done means insertion preserves the intentionally typed
and deletion still behaves correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.