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

FIX Allow wrapping an image in a link #1577

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Sep 6, 2023

Supercedes #1571

Make sure you check the installer CI run linked in the issue to see behat passing happily

Required for

Issue


// If the selected node type can contain text, and we didn't find selected text above,
// then you haven't got a selection we can wrap in a link.
const x = document.createElement(node.nodeName);
Copy link
Member

Choose a reason for hiding this comment

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

What is the point of this? Seems like it will will always return false since we're just testing an element we're creating ourselves? Or is there some sort of difference between browsers?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're essentially getting the browser to check for us if this node can have text. If it can have text, and we didn't have any text selected, then this selection isn't valid for wrapping a link, since we'd want the link to wrap the text.

If this element cannot have text, then we go into the next set of conditional statements to see if this is an element that can be wrapped inside a link (like img), or if it's something that cannot (like iframe or another link)

Copy link
Member

Choose a reason for hiding this comment

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

OK sorry I totally missed the bit where node is variable :)

// Check if there is a single selected node which can be wrapped in a link.
if (node === selection.getSel().focusNode && node === selection.getSel().anchorNode) {
const parsed = tinymce.activeEditor.dom.createFragment(`<a>${node.outerHTML}</a>`);
if (parsed.childNodes.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Again this seems really odd because we're testing the length of something that we're creating ourselves that seems like it will always return the same result?

Copy link
Member Author

@GuySartorelli GuySartorelli Sep 6, 2023

Choose a reason for hiding this comment

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

As above, except for this one we need tinymce to check if for us instead since tinymce may have its own parsing rules and allowed combinations.

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Tested locally, works good

@emteknetnz emteknetnz merged commit c9913dc into silverstripe:1.13 Sep 6, 2023
12 checks passed
@emteknetnz emteknetnz deleted the pulls/1.13/wrap-img-with-link branch September 6, 2023 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants