Problem/motivation

Linkit + CKEditor5 Plugin Pack (to enable target|_blank)
No other modules enabled.

Steps to reproduce

1.
- type in multiple words
- select, insert a link
- open attributes, select open in new tab
- Exception thrown:

ckeditor5-dll.js?v=45.2.2:5 Uncaught CKEditorError: attribute-operation-range-not-flat
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-attribute-operation-range-not-flat
    at zs._validate (ckeditor5-dll.js?v=45.2.2:5:391176)
    at on.priority (ckeditor5-dll.js?v=45.2.2:5:470168)
    at qi.fire (ckeditor5-dll.js?v=45.2.2:5:638431)
    at <computed> [as applyOperation] (ckeditor5-dll.js?v=45.2.2:5:641978)
    at d (ckeditor5-dll.js?v=45.2.2:5:455429)
    at Ai (ckeditor5-dll.js?v=45.2.2:5:455476)
    at xi.setAttribute (ckeditor5-dll.js?v=45.2.2:5:447194)
    at linkit.js?t6a4bs:1:2404
    at Array.forEach (<anonymous>)
    at n (linkit.js?t6a4bs:1:2382)

Linkit attempts seting attributes writer.setAttribute(attribute, extraAttributeValues[attribute], range); and range is not flat.
2.
- type ONE word text
- select, insert a link
- open attributes, select open in new tab
- Exception thrown:
Uncaught CKEditorError: document-selection-wrong-position {"range":{"start":{"root":"main","path":[1,null],"stickiness":"toNext"},"end":{"root":"main","path":[1,null],"stickiness":"toPrevious"}}}

Proposed resolution

fix it?

This module uses Gitlab CI for automated testing of proposed code changes. To contribute code changes, create a merge request. Patch files will not trigger automated testing and are not sufficient for review.
CommentFileSizeAuthor
#3 linkit-fix.mov13.69 MBjannakha
linkit.mov31.86 MBjannakha

Issue fork linkit-3559805

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jannakha created an issue. See original summary.

jannakha’s picture

Status: Active » Needs review
StatusFileSize
new13.69 MB

"target" attribute modification is not related to Linkit attributes, so ideally Linkit should not even bother updating its own attributes.

As a temporary workaround the show-stopping errors, I added try/catch blocks. It doesn't affect functionality of Linkit, but prevents errors.
More investigation required - where the range is changed, why it's not flat, etc.

- see video of "fix"
- in minimised version, console.logs are removed in build step

rossb89’s picture

This patch will no longer apply against dev as #3557993: [CKEditor v45+] Triple-clicking to select an item for linking triggers JS error has now been merged in.

This issue could do with some one who is well versed in linkit from taking a look at why it's selections are not flat as ckeditor expects.

It looks like editor_advanced_link has had it's own fix in (for the same / similar thing?) in #3534699: [CKEditor5 v45+] Attributes can overwrite other attributes and editing displayed text from collapsed selection generates multiple links , but linkit is still throwing these exceptions.

This MR works as a sticking plaster but a proper solution in the linkit code would be good to negate the need to have the sticking plaster :)

romixua made their first commit to this issue’s fork.

romixua’s picture

The problem was, that linkText.length returns undefined,

let newRange = writer.createRange(range.start, range.start.getShiftedBy(linkText.length));

which further transmits the wrong range, which results in an error "CKEditorError: attribute-operation-range-not-flat"

mark_fullmer’s picture

Title: Multiple exceptions when using Linkit with other modules » When link text is null, exception thrown: CKEditorError: attribute-operation-range-not-flat
mark_fullmer’s picture

Status: Needs review » Fixed

Thanks for identifying the incorrect variable assignment, @romixua! Merged and setting to "Fixed."

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

jannakha changed the visibility of the branch 3559805-multiple-exceptions-when to hidden.

jannakha’s picture

I'll apply this to editor advanced link too.
good find!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.