-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add customCopy event handler for copy #484
The head ref may contain hidden characters: "67-\u529F\u80FD\u6DFB\u52A0\u81EA\u5B9A\u4E49\u590D\u5236-hook"
Conversation
functionality
|
WalkthroughThe pull request introduces a new optional Changes
Sequence DiagramsequenceDiagram
participant User
participant Editor
participant CopyHandler
participant CustomCopyFunc
User->>Editor: Triggers Copy Event
Editor->>CopyHandler: Invoke handleOnCopy
CopyHandler->>CopyHandler: Check for customCopy
alt Custom Copy Defined
CopyHandler->>CustomCopyFunc: Invoke with editor and event
CustomCopyFunc->>CopyHandler: Modify clipboard data
end
CopyHandler->>Editor: Complete Copy Operation
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (2)
packages/core/src/text-area/event-handlers/copy.ts (1)
23-27
: Enhance error handling forcustomCopy
.Currently, if
customCopy
throws an exception, it will bubble up and potentially disrupt the editor flow. Consider wrappingcustomCopy
in a try-catch block or ensuring robust error handling within thecustomCopy
implementation to avoid breaking the copy logic.Here is a sample diff you might consider:
const { customCopy } = editor.getConfig() if (customCopy) { - customCopy(editor, event) + try { + customCopy(editor, event) + } catch (err) { + console.error('Error in customCopy handler:', err) + } }packages/core/src/config/interface.ts (1)
217-220
: Add documentation or code comments forcustomCopy
.It's recommended to provide inline comment examples or a reference to guidance on implementing a secure and effective copy handler, since incorrectly modifying
clipboardData
can degrade user experience.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/core/src/config/interface.ts
(1 hunks)packages/core/src/text-area/event-handlers/copy.ts
(1 hunks)
There was a problem hiding this 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)
.changeset/tasty-dragons-applaud.md (1)
6-6
: Enhance the changeset description with more detailsWhile the description indicates the addition of a customCopy event handler, it would be helpful to include:
- Parameters and return type of the customCopy handler
- Basic usage example
- Any migration notes if applicable
Consider expanding the description like this:
-feat: add customCopy event handler for copy +feat: add customCopy event handler for copy + +Adds a new optional `customCopy` configuration option that allows customizing the copy behavior: + +```ts +interface IEditorConfig { + customCopy?: (editor: IDomEditor, e: ClipboardEvent) => void +} +``` + +Example usage: +```ts +const editor = createEditor({ + customCopy: (editor, e) => { + // Custom copy handling logic + } +}) +```
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.changeset/tasty-dragons-applaud.md
(1 hunks)
🔇 Additional comments (1)
.changeset/tasty-dragons-applaud.md (1)
1-4
: LGTM on version bumps!
The patch version bumps for both packages are appropriate since this is a backwards-compatible feature addition.
functionality
Changes Overview
Implementation Approach
Testing Done
Verification Steps
Additional Notes
Checklist
Related Issues
Summary by CodeRabbit
New Features
customCopy
configuration to modify copy behavior.Improvements