editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Proposal/clear link tool state

Open akulistus opened this issue 7 months ago • 1 comments

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

akulistus avatar Apr 21 '26 22:04 akulistus

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:

  1. 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.
  2. Introduce a new method (e.g., handleItemChange) that triggers a dedicated function inside the inline-link tool to restore the initial selection.
  3. Pass a flag to distinguish between user-initiated clicks and programmatic ones, and handle selection restoration based on that context.

akulistus avatar Apr 23 '26 09:04 akulistus