Skip to content

fix(link): handle single-character and whitespace selections - #1321

Open
ReFFaT wants to merge 6 commits into
mainfrom
fix/link-placeholder-selection
Open

ReFFaT wants to merge 6 commits into
mainfrom
fix/link-placeholder-selection

Conversation

@ReFFaT

@ReFFaT ReFFaT commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Selecting a single character in the middle of a paragraph and pressing Ctrl/Cmd+K creates an empty link without opening its editor. Selecting only whitespace can also leave an empty link behind.

Reject whitespace-only text selections before applying a link mark. Recognize placeholder links at the start of a non-inclusive mark so a single character, including one surrounded by whitespace, opens the URL popup. Correct the tooltip's node offsets and use a half-open range so an adjacent existing link is not selected instead. Keep the existing boundary behavior for saved links.

Add command/tooltip regression tests and browser scenarios for saving and cancelling single-character links and rejecting whitespace-only selections.

Validation:

  • Editor Vitest suite: 966 passed, 13 skipped.
  • New regression tests against the original implementation: 13 failed; all pass with the fix.
  • Editor and demo TypeScript checks, package builds, ESLint (no errors), and Prettier checks passed.
  • Containerized Playwright was attempted but could not run: the local Podman environment failed with readlink .../containers/storage/overlay: invalid argument after an earlier stale dependency cache failure. Browser scenarios still need a successful CI run.

Summary by Sourcery

Fix link creation and tooltip behavior for single-character and whitespace selections.

Bug Fixes:

  • Prevent empty links from being created for whitespace-only selections.
  • Ensure single-character and whitespace-surrounded selections open the link editor correctly without selecting adjacent links.
  • Preserve existing saved-link boundary behavior while correcting tooltip anchoring.

Tests:

  • Add editor regression coverage for whitespace rejection, tooltip anchoring, adjacent links, and saved-link boundaries.
  • Add browser scenarios covering saving and cancelling single-character links and linking text across breaks and spaces.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@gravity-ui

gravity-ui Bot commented Oct 5, 2026

Copy link
Copy Markdown

Storybook Deployed

@gravity-ui

gravity-ui Bot commented Oct 5, 2026

Copy link
Copy Markdown

🎭 Playwright Report

Comment thread packages/editor/src/extensions/markdown/Link/actions/linkEnhanceActions.ts Outdated
Comment thread packages/editor/src/extensions/markdown/Link/actions/linkEnhanceActions.ts Outdated
Comment thread packages/editor/src/extensions/markdown/Link/plugins/LinkTooltipPlugin/index.tsx Outdated
Comment thread demo/tests/visual-tests/playground/Link.visual.test.tsx Outdated
Comment thread packages/editor/src/extensions/markdown/Link/actions/linkEnhanceActions.ts Outdated

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants