Issue #610Opened December 6, 2017by duskhacker8 reactions

Inserting/Editing links is hard

Question

You can only insert them in particular places, and making them "inline" is impossible. By "inline" I mean; I'm writing a line of text, and I want to put a link there, with some highlighted words that are the link, and continue with the words of the line. This is a very typical action and GrapesJS just won't let me do it.

Once you do get it dropped somewhere, it's hard to get the editor to actually edit them. You have to time the double-click, then click, just right to get it into the edit mode. I can't imagine giving my users that.

I'm going to give up and disable links altogether for my project, since I'm using the email preset, and the target document is an email, I'm going to rely on the typical email client's functionality of making a link clickable. I'm hopeful that this gets worked out in the near future. I understand that it's probably a hard problem.

Answers (3)

ryandebaDecember 7, 20174 reactions

Hi @duskhacker,

I agree that link inserting/editing is not as intuitive as I would like, and am currently working on customizing it through a plugin. Here's a brief outline of what I'm working on, let me know if you're interested and I can provide the code (it's currently buried in a single plugin with lots of other customizations, so I'd need to do some work to isolate it):

  • Link editing is done through a custom modal rather than the component settings
  • When creating new link through the RTE toolbar (clicking the "link" button), the modal immediately appears and allows you to configure the link options (href, title, content)
  • You can also open the modal by double clicking on an existing link. This kind of gets in the way of enabling the RTE, but I think it's a fair trade-off since you can edit the link content/text from the modal.
  • The modal provides a more user friendly way to create different types of links (mailto, custom url, pre-defined links, anchor)
  • I am also disabling all the default traits for links (might replace it with a custom "Edit Link" button...not sure yet) so that there is only 1 way to change the link attributes
artfJanuary 27, 20213 reactions

Hi @lahdekorpi I think something like this should work

      result: rte => {
       // Use a custom attribute in order to find the component later
        rte.insertHTML(`<span data-selectme>${rte.selection()}</span>`);
        const sel = editor.getSelected(); // get the currect selected text component
        sel.once('rte:disable', () => {
          const toSel = sel.find('[data-selectme]')[0]; // Find the componenet to select
          const attr = toSel.getAttributes();
          delete attr['data-selectme'];
          toSel.setAttributes(attr); // remove the custom attribute
          toSel.set('selectable', true); // ensure the component is selectable
          editor.select(toSel);
        });
        sel.trigger('disable'); // disables editing on the current component (this will also trigger the parser)
      },
artfApril 8, 20221 reactions

@YevhenShashnin updated the example as the RTE enable/disable functions became asynchronous.

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.