Cannot add link to media in CKEditor

Created on 17 March 2019, almost 6 years ago
Updated 30 September 2023, about 1 year ago

I get the following JS error (resulting in a page with json output):
Uncaught TypeError: Cannot read property 'collapsed' of undefined
which occurs on line 167 of /linkit/editors/ckeditor/plugin.js (which is line 4 in the following snippet):

    if (!Drupal.settings.linkit.currentInstance.selectedElement) {
      // We have not selected any link element so lets create a new one.
      var range = selection.getRanges(1)[0];
      if (range.collapsed) {
        var content = (Drupal.settings.linkit.currentInstance.linkContent) ? Drupal.settings.linkit.currentInstance.linkContent : data.path;
        var text = new CKEDITOR.dom.text(content , editor.document);
        range.insertNode(text);
        range.selectNodeContents(text);
      }

To reproduce:
– Add image with Media (7.x-2.21)
– Select the image
– click on linkit button in CKEditor (7.x-1.18) toolbar
– add URL
– click on "Insert link"
using version 7.x-3.5

It appears that the current selection is lost (selection.getRanges(1) gives an empty array) when the modal of LinkIt opens.
Adding links to other content works fine though.

🐛 Bug report
Status

Closed: outdated

Version

3.0

Component

Code

Created by

🇳🇱Netherlands inascon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States mark_fullmer Tucson

    Due to the fact that the 7.x branch is no longer receiving active development and this issue has not been updated in 4 years, as the maintainer, I'm going to close this issue in order to better manage this module's top priority issues.

    If the community feels this issue should be revisited, I'm happy to listen.

Production build 0.71.5 2024