Issue #1714Opened January 7, 2019by chiqui3d0 reactions

auto select componet in RTE

Question

When I add a link from RTE, it is not selected as the link component, I have to deselect the parent component that is the TEXT and select again, because this does not do it directly? I thought the advantage of RTE was that, that if I add a component from RTE the TRAIT options of that component will be shown. Not that I have to exit the TEXT again :(

Answers (3)

chiqui3dJanuary 7, 20190 reactions

I don't know if it's the right way, but I got it this way:

    const rte    = editor.RichTextEditor;
    rte.remove('link');
    rte.add('link', {
        icon: `<i class="fa fa-link"></i>`,
        attributes: {
            title: 'Link',
        },
        result: rte => {
            const anchor      = rte.selection().anchorNode;
            const nextSibling = anchor && anchor.nextSibling;
            if (nextSibling && nextSibling.nodeName === 'A') {
                rte.exec('unlink');
            } else {
                const html = `<a data-gjs-type="link" class="link selected" href="#">${rte.selection()}</a>`;
                rte.insertHTML(html);
                const selectedText      = editor.getSelected();
                const selectedTextInner = rte.el.innerHTML;
                selectedText.set('content', selectedTextInner);
                editor.select(selectedText.find('.selected'));
                editor.getSelected().removeClass('selected');
            }
        }
    });
artfJanuary 13, 20190 reactions

I thought the advantage of RTE was that, that if I add a component from RTE the TRAIT options of that component will be shown. Not that I have to exit the TEXT again :(

You're right @chiqui3d but when you're editing, the HTML text is "flat", so only when you disable the RTE the text is parsed and transformed in Components. Your solution actually works (and is ok) because of this selectedText.set('content', selectedTextInner) and the listener on content property

lock[bot]January 13, 20200 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.