Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare diff isn't working #212

Closed
2 tasks done
emteknetnz opened this issue May 20, 2021 · 8 comments · Fixed by #237
Closed
2 tasks done

Compare diff isn't working #212

emteknetnz opened this issue May 20, 2021 · 8 comments · Fixed by #237
Assignees
Labels

Comments

@emteknetnz
Copy link
Member

emteknetnz commented May 20, 2021

CWP-2.8.0-rc1

I can "compare" versions, though there is not a content diff i.e. the green/red diff of text changes between versions

Instead it seemed like it only showed the most recent version

I see this on /admin/pages/history/show/6132

image

The content 'diff text' is on the latest version, but not the older version that I'm comparing against

Tested in IE11 and Firefox

Acceptance Criteria

  • Text added without a matching deleted sample is highlighted in green
  • Deleted text style is retained

Notes

  • This never worked in Safari before ... we don't expect it to.
  • There's a weird code snippet that's been copied in our codebase to handle the diff generation. If it's possible to patch it, great! Otherwise we might need to look for an alternative library.

Pull Requests

@maxime-rainville
Copy link
Contributor

I'm only getting a diff when content is deleted/replace.

When brand new content is added that doesn't get highlighted.

Initial version

image

Updated version

image

Diff

image

@brynwhyman
Copy link

This was called out as a regression but I'm wondering if it indeed is... There are some related issues out there already:

@emteknetnz
Copy link
Member Author

Replicated in cms 4.7.x-dev - so it's not a regression, it's an existing issue

@GuySartorelli
Copy link
Member

What's happening

This is a styling issue. It is caused by the <ins> tag surrounding the new <p> tag and its content. Deletions of entire paragraphs also don't get the appropriate background-color applied, though the deleted content does get strikethrough applied.
ins and del elements are allowed to contain p (and other block-level) tags, but then their display style must be changed, as it's inline by default.

Easy solution: Use display: inline-block

There's unfortunately no parent selector in css yet, so I can't add a style that says "style any ins or del elements that contain p or div tags with display:block. Setting all ins or del tags to display:inline-block will slightly change the appearance of the tags, but is definitely the easiest solution.

Current appearance:
image

Using inline-block:
image

Harder solution: Push the del and ins tags inside the block-level elements.

We could check for any del and ins tags that contain block-level elements, and invert them so the block-level element instead contains the del or ins tag. This will retain the current styling, but may look a little strange for longer paragraphs - not sure which is more desirable. This approach also has more edge cases (e.g. making sure we catch all block-level elements, plus what happens with nested block-level elements?)
This can be done either with an HTML parser in the php code or using javascript on the client-side.

@emteknetnz
Copy link
Member Author

The inline-block solution seems fine and unlikely to cause regressions? Is there actually a downside to going with this?

@GuySartorelli
Copy link
Member

I can't think of any downside provided there's no complaints about the slight style change.
I'm aware we used to have a designer in product to look at stuff like this so I figured in lieu of that I'd just give you and Max a chance to let me know if it's okay before I make the change.

@emteknetnz
Copy link
Member Author

Go for it

@GuySartorelli GuySartorelli linked a pull request Apr 10, 2022 that will close this issue
@GuySartorelli GuySartorelli removed their assignment Apr 10, 2022
@emteknetnz emteknetnz self-assigned this Apr 11, 2022
@emteknetnz
Copy link
Member Author

Linked PR has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants