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?
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | linkit-fix.mov | 13.69 MB | jannakha |
| linkit.mov | 31.86 MB | jannakha |
Issue fork linkit-3559805
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
Comment #3
jannakha commented"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
Comment #4
rossb89 commentedThis 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 :)
Comment #7
romixuaThe problem was, that linkText.length returns undefined,
which further transmits the wrong range, which results in an error "CKEditorError: attribute-operation-range-not-flat"
Comment #8
mark_fullmerComment #9
mark_fullmerThanks for identifying the incorrect variable assignment, @romixua! Merged and setting to "Fixed."
Comment #13
jannakha commentedI'll apply this to editor advanced link too.
good find!