ckeditor_textselection
CKEditor Text Selection
A Drupal module that integrates the CKEditor 5 Text Selection plugin into Drupal's CKEditor 5 editor.
This module makes the editor keep its text selection when switching between WYSIWYG and Source mode, and scrolls the selection into the viewport. It replicates the behaviour of the popular CKEditor 4 Text Selection addon for CKEditor 5.
How it works
When switching from WYSIWYG to Source mode, the plugin maps the current cursor position or text selection from the editor model to the corresponding position in the raw HTML source. When switching back from Source to WYSIWYG, it reads the cursor position in the source textarea and restores it in the rich text editor.
All failures are handled silently — the editor never crashes.
Features
- Preserves cursor position when toggling between WYSIWYG and Source editing modes.
- Preserves text selection (not just cursor) across mode switches.
- Scrolls the viewport to show the selection in both modes.
- Works with the CKEditor CodeMirror Source Editing plugin.
- Inspired by the CKEditor 4 Text Selection plugin.
Requirements
- CKEditor 5 Source Editing must be enabled in the text format configuration.
Installation
- Install the module as you would normally install a contributed Drupal module. See Installing modules for further information.
- Go to Administration > Configuration > Content authoring > Text formats and editors.
- Configure a text format that uses CKEditor 5.
- Under CKEditor 5 plugin settings, enable the Text Selection plugin.
- Make sure Source Editing is also enabled in the toolbar.
Configuration
No additional configuration is required. Once enabled, the plugin automatically preserves text selection when switching between editing modes.
Related projects
Maintainers
DrupalBook agency created CKEditor Text Selection for Drupal and specializes in building clean, reliable CKEditor plugins tailored to real editorial workflows. If you need a custom CKEditor feature, deeper Drupal integration, or long‑term maintenance by someone who knows both ecosystems inside out, We are happy to help. Get in touch to discuss your project: [email protected] or https://drupalbook.org/contact.