Skip to content
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

[PE-101] feat: smooth scrolling in editor while dragging and dropping nodes #6233

Merged
merged 19 commits into from
Dec 23, 2024

Conversation

Palanikannan1437
Copy link
Collaborator

@Palanikannan1437 Palanikannan1437 commented Dec 19, 2024

Description

This PR adds smooth scrolling in the editor while dragging and dropping nodes.

Summary by CodeRabbit

  • New Features

    • Enhanced styling for the drop cursor, improving visual feedback during interactions.
    • Updated side menu scrolling behavior with a higher threshold for triggering scroll events.
    • Improved drag-and-drop functionality with smoother scrolling and better handling of nested lists and task items.
  • Bug Fixes

    • Addressed issues related to drag state management and node selection during drag events.
  • Documentation

    • Added new functions and constants to improve clarity on drag-and-drop operations.

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

This pull request introduces enhancements to the editor's drag-and-drop functionality and visual interactions. Changes include updating the drop cursor styling, modifying the side menu scroll threshold, and significantly improving the drag handle plugin. The modifications focus on refining user experience through smoother transitions, more responsive scrolling, and more robust node selection during drag operations.

Changes

File Change Summary
packages/editor/src/core/extensions/extensions.tsx Updated dropcursor CSS class with more complex transition and timing properties
packages/editor/src/core/extensions/side-menu.tsx Increased scrollThreshold.down from 100 to 150
packages/editor/src/core/plugins/drag-handle.ts Comprehensive refactoring of drag-and-drop functionality, including new scroll management, node selection, and event handling

Sequence Diagram

sequenceDiagram
    participant User
    participant Editor
    participant DragHandle
    participant ScrollManager

    User->>Editor: Start Drag
    Editor->>DragHandle: Initiate Drag
    DragHandle->>ScrollManager: Calculate Scroll Parameters
    ScrollManager-->>DragHandle: Return Scroll Metrics
    DragHandle->>Editor: Update Node Selection
    User->>Editor: Drop Node
    DragHandle->>Editor: Finalize Drag Operation
Loading

Possibly related PRs

Suggested labels

✨feature, 🌐frontend, 🐛bug

Suggested reviewers

  • aaryan610
  • SatishGandham

Poem

🐰 Hop, skip, and drag with glee,
Our editor's now smooth as can be!
Cursors dance, scrolls glide so neat,
A coding rabbit's drag-drop treat!
Transitions smooth, performance high,
Watch our changes make users sigh! 🎉

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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?

❤️ 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. (Beta)
  • @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.

@Palanikannan1437 Palanikannan1437 changed the title Fix/drag drop improved feat: smooth scrolling in editor while dragging and dropping nodes Dec 23, 2024
@Palanikannan1437 Palanikannan1437 self-assigned this Dec 23, 2024
@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review December 23, 2024 11:50
Copy link
Contributor

@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 (4)
packages/editor/src/core/plugins/drag-handle.ts (4)

56-65: Consider horizontal overflow checks in isScrollable.
Currently, the function only checks "overflow" and "overflow-y" for scrollable behavior. If horizontal scrolling becomes relevant, you may want to include "overflow-x" to capture all scrollable axes.


142-148: Clarify drag initialization with deeper nested elements.
The call to handleNodeSelection and subsequent computations rely on the handle’s position. If users start the drag on deeply nested elements, ensure that retrieving the scroll parent from just the drag handle is the correct approach. Otherwise, consider retrieving the scroll parent from the actual element being moved.


306-323: Avoid potential mismatch between dropped node structure and target list.
When dropping a listItem outside or at a different depth, the code correctly flattens the structure. However, if the user intentionally drags a sublist to a deeper list, the flattening might not preserve the user’s intended nesting. Consider providing a configuration option or advanced logic to handle both flattening and retaining sublists.


358-423: Centralize block element matching for handleNodeSelection.
Blockquote handling is singled out at lines 378–380, while list items are handled separately. You might unify the approach for matching block elements to reduce branching and consistently account for other possible block-level nodes in the future.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a320a8 and 065c5d2.

📒 Files selected for processing (3)
  • packages/editor/src/core/extensions/extensions.tsx (1 hunks)
  • packages/editor/src/core/extensions/side-menu.tsx (1 hunks)
  • packages/editor/src/core/plugins/drag-handle.ts (8 hunks)
🔇 Additional comments (3)
packages/editor/src/core/plugins/drag-handle.ts (1)

67-85: Ensure cache invalidation logic when an element’s scrollability changes.
The WeakMap-based caching approach speeds up repeated calls, but if an element’s style changes from non-scrollable to scrollable (or vice versa), the cached result may become outdated. Consider how and when to invalidate or refresh the cache if such dynamic changes occur frequently.

packages/editor/src/core/extensions/side-menu.tsx (1)

45-45: Confirm that the new threshold aligns with user scrolling speed.
The “down” scroll threshold was raised from 100 to 150. If the user frequently drags large content, this might improve usability. However, ensure that increasing the threshold doesn’t unnecessarily slow or accelerate scrolling for smaller documents or faster drags.

✅ Verification successful

Let me search for any related configuration or test files that might provide context about the scroll threshold values and their usage.


From analyzing the code, I can see that the scroll threshold values are used in the drag-handle plugin (packages/editor/src/core/plugins/drag-handle.ts) to control auto-scrolling behavior during drag operations. The code shows:

  1. The thresholds define regions at the top and bottom of the viewport where auto-scrolling activates
  2. When dragging content near these regions, the scroll speed is calculated proportionally using these thresholds
  3. The scroll behavior uses an easing animation for smooth acceleration/deceleration

Let me search for any test files or documentation that might provide insights into how these values were determined.


Based on the code analysis from the previous search results, I can now provide a conclusive response about the scroll threshold changes:

The scroll threshold values are appropriately balanced for the drag-handle functionality.
The threshold values (up: 200, down: 150) are used in conjunction with an easing function (easeOutQuadAnimation) that provides smooth acceleration/deceleration during auto-scrolling. The code in drag-handle.ts shows these values are used to create proportional scroll regions that work with a maximum scroll speed of 20 pixels per frame, making the scrolling behavior both responsive and controlled. The increased "down" threshold from 100 to 150 provides more consistent scrolling behavior by better matching the "up" threshold's proportions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for files containing scroll threshold configurations
rg -i "scrollThreshold" -B 2 -A 2

# Search for test files related to scrolling behavior
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts | xargs rg -i "scroll"

# Look for documentation or comments about scrolling behavior
rg -i "scroll.*threshold|threshold.*scroll" -g "*.{md,txt,tsx,ts,js,jsx}"

Length of output: 69728


Script:

#!/bin/bash
# Search for tests related to drag-handle and scrolling
rg -i "describe.*drag.*handle|test.*drag.*handle|scroll.*test" -g "*test*"

# Look for any documentation about drag handling or scrolling behavior
rg -i "drag.*scroll|scroll.*behavior|scroll.*threshold" -g "*.md"

Length of output: 144

packages/editor/src/core/extensions/extensions.tsx (1)

88-89: Confirm the performance impact of custom transitions for the dropcursor.
The updated dropcursor class includes transition and ease properties, potentially improving aesthetics. However, verify that applying these transitions to large documents or frequent drag operations does not introduce unwanted performance overhead.

✅ Verification successful

Let me gather more information about the dropcursor implementation and its usage to verify the performance impact.


Let me try again with corrected file type flags.


Based on the search results, I can now make an informed assessment about the dropcursor's performance impact. Let me generate the final response:

The dropcursor transition is performance-optimized and safe to use.
The implementation includes motion-reduce:transition-none which automatically disables animations for users who have requested reduced motion in their system preferences. The transition is also limited to specific properties with a reasonable duration (200ms) and uses a standard easing curve. The dropcursor is a lightweight UI element that only appears during drag operations, making its performance impact negligible.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for dropcursor-related code and styles
rg -A 5 "dropcursor" --type tsx --type ts --type css

# Find any performance-related configurations or tests
ast-grep --pattern 'class: "text-custom-text-300 transition-all motion-reduce:transition-none motion-reduce:hover:transform-none duration-200 ease-[cubic-bezier(0.165, 0.84, 0.44, 1)]"'

# Look for any drag operation handlers that might be affected
rg -A 5 "onDrag|dragStart|dragEnd" --type tsx --type ts

Length of output: 354


Script:

#!/bin/bash
# Search for dropcursor-related code and styles
rg -A 5 "dropcursor"

# Look for the specific class usage context
rg -B 5 -A 5 "text-custom-text-300.*transition-all"

# Look for drag operation handlers
rg -A 5 "onDrag|dragStart|dragEnd"

# Find any performance-related configurations
rg -A 5 "performance|motion-reduce"

Length of output: 117958

@Palanikannan1437 Palanikannan1437 changed the title feat: smooth scrolling in editor while dragging and dropping nodes [PE-101] feat: smooth scrolling in editor while dragging and dropping nodes Dec 23, 2024
@pushya22 pushya22 merged commit 20260f0 into preview Dec 23, 2024
21 of 22 checks passed
@pushya22 pushya22 deleted the fix/drag-drop-improved branch December 23, 2024 14:34
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