Skip to content

Conversation

@kaueburiti
Copy link

Context

This PR responds to the issue Editor Bullet into Link #22822 posted on the Ghost repository.

The Problem

When pasting a link inside a list item, we get an unexpected behavior:

  1. An embed link preview is created outside the list
  2. The list item remains empty

CleanShot 2025-04-15 at 20 01 50

The Solution

  1. Detect when the link pasting is happening inside a list item
  2. Avoid embed card creation
  3. Create a simple link inside the list item

CleanShot 2025-04-15 at 20 10 03

Original Issue: Editor Bullet into Link #22822 (TryGhost/Ghost#22822?)

Avoid creating an embed/bookmark when pasting a link inside a list item, creating a simple link inside the list item.
@coderabbitai
Copy link

coderabbitai bot commented Apr 15, 2025

Walkthrough

The changes update the paste handling logic for URLs in the Koenig Lexical editor. The logic now includes explicit checks to determine if the current node is a card shortcut (text starting with a slash) or a list item. If a card shortcut is detected, the conversion of pasted URLs into embeds, bookmarks, or links is prevented. If the node is a list item, pasting a URL results in the URL being wrapped as a hyperlink within the list item, rather than being converted into an embed or bookmark. Only if neither condition applies does the logic proceed to convert the URL into an embed, bookmark, or link. Corresponding end-to-end tests were added to verify that pasting a URL inside a list item results in a hyperlink and not an embed or bookmark. The test suite also imports a new utility function, pasteLexical, to assist with setting up the editor state for testing.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/koenig-lexical/src/plugins/KoenigBehaviourPlugin.jsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "react-app" to extend from. Please check that the name of the config is correct.

The config "react-app" was referenced from the config file in "/packages/koenig-lexical/.eslintrc.cjs".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

packages/koenig-lexical/test/e2e/paste-behaviour.test.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "react-app" to extend from. Please check that the name of the config is correct.

The config "react-app" was referenced from the config file in "/packages/koenig-lexical/.eslintrc.cjs".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/koenig-lexical/src/plugins/KoenigBehaviourPlugin.jsx (1)

1302-1302: Consider using optional chaining for safer node access

The code could use optional chaining to prevent potential null reference errors when accessing the node's text content.

-        const isNodeCardShortcut = node && node.getTextContent().startsWith('/');
+        const isNodeCardShortcut = node && node?.getTextContent().startsWith('/');
🧰 Tools
🪛 Biome (1.9.4)

[error] 1302-1302: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c48c9af and 884e194.

📒 Files selected for processing (2)
  • packages/koenig-lexical/src/plugins/KoenigBehaviourPlugin.jsx (1 hunks)
  • packages/koenig-lexical/test/e2e/paste-behaviour.test.js (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/koenig-lexical/test/e2e/paste-behaviour.test.js (1)
packages/koenig-lexical/test/utils/e2e.js (5)
  • focusEditor (58-61)
  • pasteLexical (315-317)
  • paste (283-305)
  • assertHTML (63-106)
  • html (188-197)
🪛 Biome (1.9.4)
packages/koenig-lexical/src/plugins/KoenigBehaviourPlugin.jsx

[error] 1302-1302: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (2)
packages/koenig-lexical/test/e2e/paste-behaviour.test.js (1)

627-671: Well-structured test for the list item URL pasting behavior!

This test case properly verifies the fixed behavior from the PR objectives: that pasting a URL inside a list item results in a simple hyperlink rather than an embed/bookmark card. The test is well-structured with clear setup, execution, and verification steps.

packages/koenig-lexical/src/plugins/KoenigBehaviourPlugin.jsx (1)

1300-1319: Good implementation of the list item link pasting fix!

The changes correctly implement the fix described in the PR by:

  1. Clearly identifying when a node is a list item
  2. Creating a standard link node instead of an embed/bookmark when pasting URLs in list items
  3. Properly appending the link to the list item

This fix ensures that pasted URLs remain as simple hyperlinks within list items rather than being converted to embed cards outside the list.

🧰 Tools
🪛 Biome (1.9.4)

[error] 1302-1302: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Copy link
Member

@kevinansfield kevinansfield left a comment

Choose a reason for hiding this comment

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

@kaueburiti thanks for taking a look at this! 🙌

Looking at the changes, I think the handling is done in the wrong place here. I'd prefer to see the behaviour inside the PASTE_LINK_COMMAND handler.

With the current approach we lose the ability to paste a URL onto highlighted text inside a list and have that text converted into a link (adding a test to confirm this would be helpful 🙏). If the handling is instead inside the PASTE_LINK_COMMAND handler then we can be more selective over the behaviour, pasting a link directly when no text is selected when inside a list and keeping the convert-text-to-link behaviour when there is a selection.

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.

2 participants