Problem/Motivation
After the fix from #3334784: Implement Token-Click-Insert for CKEditor 5, it's now possible again to add tokens in CKEditor 5. The issue that I'm experiencing is that when initially you focus on a text field and then focus on a CKEditor, the token is being added to the text field while the last focus was on the CKEditor.
Steps to reproduce
- Have a content type available with CKEditor 5 (with Token Browser enabled on the editor) on a long text field
- Create or edit a node
- Click on the title field
- Click on the CKEditor, fill in text (to be sure we are focusing on the CKEditor)
- Click on Token Browser
- Click on a token to be inserted
- Token will be added to the title field instead of the CKEditor field
Proposed resolution
When a textarea or input text field is being focused it will have priority over CKEditor fields. I propose to set the drupalSettings.tokenFocusedField to false when a CKEditor5 instance is focused. This way the tokens will be actually inserting on last clicked fields (including CKEditor5 fields).
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3397637-focusing-back-ckeditor-wrong.patch | 2.05 KB | gnuget |
Issue fork token-3397637
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
bojan_dev commentedComment #4
bojan_dev commentedThere is a edge case were this issue is still occurring in an initial state, but this can be resolved when the
editor:attachedevent lands in core, see: #3319358: Trigger event when Text Editor is attachedWe can then do:
Comment #5
psf_ commentedWork for me, but it need a bit of debug.
The focus is directed to the correct field, but the field must be activated by clicking. Sometimes it is confusing, since when you click on the button in the CKEditor 5 toolbar, it does not receive focus.
Comment #7
andreic commentedI have a page for a client where both simple textareas and ckeditor textareas are used for different fields in different paragraphs and if I clicked first on a simple textarea field and then on ckeditor textarea field, the focus would not work and Token Browser would not insert toke values.
If I closed the token browser window and clicked again the ckeditor textarea, then it would work, but the first time after a page load, it does not.
I switched the checks in the MR (first check for tokenFocusedCkeditor5 and then for tokenFocusedField) and now it works without a problem.
Comment #8
gnugetI faced this today, but in a Layout Builder block.
The thing is, when an inline block is edited on the Layout Builder page, it automatically focuses on the first field, so the
Click on the title fieldstep is not even necessary, it just doesn’t work at all. 🥲Here’s a patch version of the PR in case someone needs it.