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

Add Vim binding support for CodePair using CodeMirror 6 #340

Merged
merged 9 commits into from
Sep 11, 2024

Conversation

choidabom
Copy link
Contributor

@choidabom choidabom commented Sep 7, 2024

What this PR does / why we need it?

This PR aims to implement Vim binding support for CodePair in the new CodeMirror 6 framework. Since the previous version relied on CodeMirror 5 and used a specific Vim binding plugin, it is important to ensure that a suitable Vim binding plugin is available for CodeMirror 6. This enhancement will benefit developers who prefer Vim key bindings, allowing them to have a familiar and efficient editing experience in CodePair.

Any background context you want to provide?

Adding Vim binding support is essential as it enhances the usability of CodePair for users who are accustomed to Vim. This will broaden the appeal of CodePair to a wider developer audience and improve overall productivity. Additionally, we plan to provide a user interface that allows users to change editor settings, including configurations for key bindings, enhancing the flexibility of the editor settings.

NOTE: I've arbitrarily designed the UI, so please let me know if you have any feedback!

What are the relevant tickets?

Fixes #158

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Integrated Vim keybindings into the CodeMirror editor for enhanced user experience.
    • Introduced a new EditorBottomBar component for selecting code key types dynamically.
  • Improvements

    • Enhanced the DocumentView component for better responsiveness and layout.
    • Updated state management to use enums for editor modes and key types, improving type safety.
    • Improved handling of user roles in the DocumentHeader component for better clarity and maintainability.

@choidabom choidabom self-assigned this Sep 7, 2024
Copy link
Contributor

coderabbitai bot commented Sep 7, 2024

Walkthrough

The changes introduce Vim keybinding support to the CodeMirror editor in the frontend project, enhancing the user experience for developers familiar with Vim. A new EditorBottomBar component allows users to select key types dynamically, and the editor's state management has been updated to accommodate these new features. Additionally, the code has been refactored for improved readability and maintainability.

Changes

File Change Summary
frontend/package.json Added dependency @replit/codemirror-vim version ^6.2.1 for Vim keybindings.
frontend/src/components/editor/*.tsx Refactored components to integrate Vim keybindings, introduced EditorBottomBar, and updated rendering logic for responsiveness and clarity.
frontend/src/store/editorSlice.ts Replaced string literal type for EditorModeType with an enum; added CodeKeyType enum and codeKey property to EditorState.
frontend/src/components/headers/DocumentHeader.tsx Updated logic to use ShareRole and EditorModeType enums for better type safety in role and mode management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant BottomBar
    participant Store

    User->>BottomBar: Selects Key Type
    BottomBar->>Store: Dispatches setCodeKeyType
    Store->>Editor: Updates codeKey
    Editor->>User: Applies Vim Key Mappings
Loading

Assessment against linked issues

Objective Addressed Explanation
Add Vim Binding Support for CodePair Using CodeMirror 6 (#158)
Provide UI for users to change editor settings (#158)

🐰 Hopping through the code with glee,
Vim bindings now, oh joy for me!
With a bottom bar to choose my way,
Editing's a breeze, come what may!
Let's code and play, hip-hip-hooray! 🌟

Tip

New features

Walkthrough comment now includes:

  • Possibly related PRs: A list of potentially related PRs to help you recall past context.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs. You can also provide custom labeling instructions in the UI or configuration file.

Notes:

  • Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 94f2a63 and cb69240.

Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (7)
  • frontend/package.json (1 hunks)
  • frontend/src/components/editor/DocumentView.tsx (4 hunks)
  • frontend/src/components/editor/Editor.tsx (6 hunks)
  • frontend/src/components/editor/EditorBottomBar.tsx (1 hunks)
  • frontend/src/components/editor/Preview.tsx (1 hunks)
  • frontend/src/components/headers/DocumentHeader.tsx (3 hunks)
  • frontend/src/store/editorSlice.ts (3 hunks)
Files skipped from review due to trivial changes (1)
  • frontend/src/components/editor/Preview.tsx
Additional comments not posted (10)
frontend/src/store/editorSlice.ts (1)

Line range hint 9-69: Review of Changes in editorSlice.ts

The introduction of EditorModeType and CodeKeyType enums is a positive change, enhancing type safety and making the code more robust and easier to maintain. The addition of the codeKey property in the EditorState and the setCodeKeyType action creator are well-implemented and necessary for the new functionality allowing users to switch key bindings dynamically.

Suggestions:

  • Ensure that all parts of the application that use these enums and state properties are updated accordingly to handle the new types.
  • Consider adding more detailed comments explaining the purpose of each enum value and state property, especially for new developers or for future reference.
frontend/src/components/editor/DocumentView.tsx (1)

Line range hint 11-96: Review of Changes in DocumentView.tsx

The conversion of DocumentView to an arrow function is a modern React practice that enhances consistency and readability. The updated rendering logic, which includes the EditorBottomBar in different editor modes, is well-thought-out and aligns with the PR's objectives to provide a consistent user interface across modes.

Suggestions:

  • Verify that all dependencies of DocumentView, such as props and context, are correctly handled in the new arrow function format.
  • Ensure that the responsiveness and functionality of the Resizable component and the EditorBottomBar are thoroughly tested, especially in different browser environments and screen sizes.
frontend/src/components/headers/DocumentHeader.tsx (3)

21-21: Approved: Import of ShareRole.

The import of ShareRole from ../../utils/share is correctly placed and enhances type safety by replacing string literals with constants.


35-36: Approved: Use of constants for role and mode checks.

Replacing string literals with ShareRole.READ and EditorModeType.read enhances type safety and code readability. This change aligns with best practices in TypeScript.


62-62: Approved: Conditional rendering using ShareRole.

The use of ShareRole.READ in the conditional rendering logic ensures that editor mode buttons are displayed only when the user's role is not read-only. This maintains the intended functionality with improved type safety.

frontend/package.json (1)

36-36: Approved: Addition of @replit/codemirror-vim dependency.

The addition of @replit/codemirror-vim at version ^6.2.1 is appropriate for integrating Vim keybindings with CodeMirror 6. Ensure to verify compatibility with other dependencies.

Run the following script to verify dependency compatibility:

Verification successful

Dependency @replit/codemirror-vim is present and appears compatible.

The @replit/codemirror-vim dependency is correctly added to frontend/package.json at version ^6.2.1. It seems compatible with the existing CodeMirror-related dependencies. However, ensure to verify runtime compatibility and integration within the application.

  • File: frontend/package.json
  • Dependency: @replit/codemirror-vim version ^6.2.1
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential conflicts with new dependency.

# Test: List all dependencies and their versions. Expect: No conflicts with `@replit/codemirror-vim`.
cat package.json | jq '.dependencies'

Length of output: 82


Script:

#!/bin/bash
# Search for the package.json file in the repository
fd package.json

Length of output: 60


Script:

#!/bin/bash
# Display the dependencies from frontend/package.json
cat frontend/package.json | jq '.dependencies'

Length of output: 1817

frontend/src/components/editor/Editor.tsx (4)

4-4: Approved: Import of Vim keybindings.

The import of Vim and vim from @replit/codemirror-vim is essential for integrating Vim keybindings into the editor. This aligns with the PR's objectives to enhance the editing experience for Vim users.


Line range hint 92-102: Approved: Setup and teardown of the editor view.

The setup and teardown of the EditorView are correctly implemented, ensuring proper memory management and preventing potential leaks. This is crucial for maintaining the editor's performance and stability.


89-90: Approved: Vim key mapping configuration.

Mapping 'jj' to '' in insert mode is a thoughtful addition for Vim users. Verify that this mapping does not conflict with other key mappings in the editor.

Run the following script to check for key mapping conflicts:

Verification successful

No conflicts found with 'jj' Vim key mapping.

The search for other Vim key mappings in the codebase revealed no additional mappings, confirming that there are no conflicts with the 'jj' mapping to '' in insert mode. This configuration is safe to use.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for key mapping conflicts.

# Test: List all key mappings. Expect: No conflicts with 'jj' mapping.
echo "Key mapping tests need to be conducted in a controlled environment."

Length of output: 144


Script:

#!/bin/bash
# Search for all instances of Vim key mappings in the codebase to check for potential conflicts with 'jj'.
rg 'Vim\.map' -A 2

Length of output: 242


71-71: Approved: Conditional application of Vim keybindings.

The conditional application of Vim keybindings based on editorStore.codeKey is a smart implementation that allows users to dynamically switch keybindings. Ensure thorough testing to confirm stability and performance.

Run the following script to verify the stability and performance:

frontend/src/components/editor/EditorBottomBar.tsx Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cb69240 and 41bc134.

Files selected for processing (1)
  • frontend/src/pages/workspace/document/share/Index.tsx (2 hunks)
Additional comments not posted (2)
frontend/src/pages/workspace/document/share/Index.tsx (2)

8-16: Approved: Enhanced type safety with enums.

The introduction of EditorModeType and ShareRole enums and their associated imports from editorSlice and share.ts enhances type safety and maintainability. This is a positive change as it avoids hard-coded string literals and aligns with best practices.


35-36: Approved: Improved readability and type safety in useEffect.

The use of ShareRole and EditorModeType enums in the useEffect hook improves code readability and type safety. This change ensures that the editor mode is set correctly based on the shared document's role, aligning with the PR's objectives to enhance user experience with Vim bindings.

frontend/src/components/editor/DocumentView.tsx Outdated Show resolved Hide resolved
frontend/src/components/editor/DocumentView.tsx Outdated Show resolved Hide resolved
frontend/src/components/editor/EditorBottomBar.tsx Outdated Show resolved Hide resolved
frontend/src/components/editor/EditorBottomBar.tsx Outdated Show resolved Hide resolved
frontend/src/store/editorSlice.ts Outdated Show resolved Hide resolved
frontend/src/store/editorSlice.ts Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 41bc134 and e8f3ffb.

Files selected for processing (9)
  • frontend/src/components/common/ThemeButton.tsx (1 hunks)
  • frontend/src/components/editor/DocumentView.tsx (4 hunks)
  • frontend/src/components/editor/Editor.tsx (6 hunks)
  • frontend/src/components/editor/EditorBottomBar.tsx (1 hunks)
  • frontend/src/components/headers/DocumentHeader.tsx (3 hunks)
  • frontend/src/components/popovers/ProfilePopover.tsx (3 hunks)
  • frontend/src/pages/workspace/document/share/Index.tsx (2 hunks)
  • frontend/src/store/configSlice.ts (2 hunks)
  • frontend/src/store/editorSlice.ts (3 hunks)
Files skipped from review as they are similar to previous changes (6)
  • frontend/src/components/editor/DocumentView.tsx
  • frontend/src/components/editor/Editor.tsx
  • frontend/src/components/editor/EditorBottomBar.tsx
  • frontend/src/components/headers/DocumentHeader.tsx
  • frontend/src/pages/workspace/document/share/Index.tsx
  • frontend/src/store/editorSlice.ts
Additional comments not posted (3)
frontend/src/components/common/ThemeButton.tsx (1)

3-18: Excellent use of enums for theme management.

The introduction of ThemeType enum enhances type safety and maintainability. The handleChangeTheme function is well-implemented, using the enum effectively to toggle between themes. This is a good practice and aligns well with modern JavaScript/TypeScript best practices.

frontend/src/store/configSlice.ts (1)

Line range hint 5-44: Well-structured configuration management enhancements.

The introduction of ThemeType and CodeKeyType enums, along with the updates to the ConfigState and the addition of setCodeKeyType, significantly enhance the type safety and maintainability of the state management. These changes are well-aligned with Redux Toolkit best practices and the PR's objectives to support dynamic key binding configurations.

frontend/src/components/popovers/ProfilePopover.tsx (1)

Line range hint 1-35: Robust and clean implementation in ProfilePopover.

The ProfilePopover component is well-organized, handling theme changes, navigation, and logout functionalities effectively. The use of ThemeType enum in handleChangeTheme function replaces string literals, enhancing type safety and maintainability. This change aligns well with the overall theme management strategy in the application.

Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

@devleejb devleejb merged commit 70beff7 into yorkie-team:main Sep 11, 2024
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 1, 2024
2 tasks
minai621 pushed a commit that referenced this pull request Nov 5, 2024
* Add Vim binding for CodePair using CodeMirror 6

* Add vim key mapping 'jj' for insert mode

* Fix argument type

* Fix components to use `function` keyword

* Add EditorBottomBar props interface

* Fix enum members to use capital letters

* Move `EditorBottomBar` into `Editor` components

* Change to `Paper` component

* Move codekey options to `configSlice`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Add Vim Binding Support for CodePair Using CodeMirror 6
2 participants