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)
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');
}
}
});
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
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.
Issue #1669
[Question] Custom link modal doesn't update the current text but add another text with link
Hello Artur, I'm trying to have a custom modal when clicked link button in RTE. but it doesn't convert selected text to link but what it do...
Issue #1095
[FEATURE REQUEST] Preselect a trait select option
Hello, I'd like you to add to the options array of a select trait a third parameter next to 'name' and 'value', which is 'selected' in orde...
Issue #374
Is it possible that I change value in traits that will directly reflected in component?
Like If I created drop-down in traits and with a select value of dropdown I want to change the text that is present in that component witho...
Issue #869
[Question] Should traits be disabled / hidden when no component is selected?
The style manager seems to have a nice solution for when no component is selected by showing a "Select an element before using Style Manage...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.