editor.js
editor.js copied to clipboard
Proposal/clear link tool state
Fixes issue (https://github.com/codex-team/editor.js/pull/2979#issuecomment-4047227787) preventing text unlinking by clicking link popover item block in toolbar. Also improves the link tool’s behavior when switching between tools in the toolbar
We need a way to restore the initial selection when a different popover item is clicked. Previously, this was handled by calling handleClick on nestedPopoverTriggerItem, but that approach caused linked text to become unlinked:
https://github.com/codex-team/editor.js/blob/4ea9eb389847181ceb757735f8bd45cc8c2f1673/src/components/utils/popover/popover-inline.ts#L166-L181
I see three possible approaches to implement this:
- Current approach: detect whether a new selection occurs within the toolbar (on another element), and restore either the initial selection or the new one accordingly.
- Introduce a new method (e.g., handleItemChange) that triggers a dedicated function inside the inline-link tool to restore the initial selection.
- Pass a flag to distinguish between user-initiated clicks and programmatic ones, and handle selection restoration based on that context.