Skip to content

Conversation

@hzionn
Copy link
Owner

@hzionn hzionn commented Jul 4, 2025

Summary

  • implement moveWordEnd utility for moving to the end of a word
  • expose new motion and bind it in the state machine
  • wire the new action through content script
  • document e word navigation in README

Testing

  • npm test (fails: could not read package.json)

https://chatgpt.com/codex/tasks/task_e_68675080db58832ebd40f0bd70562420

Summary by CodeRabbit

  • New Features

    • Added support for the 'e' key to move the cursor to the end of the current word, mimicking Vim's 'e' motion.
  • Documentation

    • Updated the README to document the new 'e' keybinding for word movement commands.

@coderabbitai
Copy link

coderabbitai bot commented Jul 4, 2025

Walkthrough

The changes introduce support for the 'e' key in Vim-like word navigation, allowing the cursor to jump to the end of the current word. Documentation, state machine mappings, action handling, and a new motion function are updated to implement and describe this behavior.

Changes

File(s) Change Summary
README.md Updated documentation to include the 'e' keybinding for jumping to the end of the current word.
src/vim-state-machine.js Added 'e' key mapping to trigger the 'moveWordEnd' action in the NORMAL state.
src/content.js Imported and integrated the new 'moveWordEnd' action into the FSM action map for keydown events.
src/vim-motions.js Added the moveWordEnd function to move the cursor to the end of the current word or punctuation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ContentScript
    participant VimStateMachine
    participant VimMotions

    User->>ContentScript: Press 'e' in NORMAL mode
    ContentScript->>VimStateMachine: Handle keydown('e')
    VimStateMachine-->>ContentScript: Action: moveWordEnd
    ContentScript->>VimMotions: moveWordEnd(element)
    VimMotions-->>ContentScript: Cursor moved to end of word
Loading

Poem

A hop, a skip, the 'e' key's delight,
Now rabbits leap to word-ends right.
With nimble paws and Vimmy flair,
The cursor bounds from here to there.
So let us cheer this hopping trend—
To every word, a proper end!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e5aed1 and 0d147aa.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • src/content.js (2 hunks)
  • src/vim-motions.js (2 hunks)
  • src/vim-state-machine.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/content.js (1)
src/vim-motions.js (1)
  • moveWordEnd (250-274)
🔇 Additional comments (6)
src/vim-motions.js (2)

250-274: LGTM! Well-implemented Vim 'e' motion with correct edge case handling.

The moveWordEnd function correctly implements Vim's 'e' motion behavior:

  • Properly handles cursor at end of text
  • Skips initial whitespace (matching Vim's behavior)
  • Correctly advances to end of word/punctuation groups
  • Uses consistent patterns with existing motion functions

The implementation is robust and follows the established codebase patterns.


501-501: Proper integration into the exported VimMotions object.

The moveWordEnd function is correctly added to the global exports, making it available for use in other modules.

README.md (1)

23-23: Clear and accurate documentation for the new 'e' motion.

The documentation entry follows the existing format and accurately describes the 'e' motion behavior.

src/vim-state-machine.js (1)

42-42: Correct integration of 'e' key mapping in the state machine.

The 'e' key is properly mapped to the 'moveWordEnd' action in the NORMAL state, following the established pattern for other movement commands.

src/content.js (2)

169-169: Proper import of moveWordEnd function.

The moveWordEnd function is correctly imported from the VimMotions module, following the established pattern for other motion functions.


336-336: Correct integration into the FSM action map.

The moveWordEnd action is properly mapped to execute the function on the active element, maintaining consistency with other movement actions.

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@hzionn hzionn requested a review from Copilot July 21, 2025 08:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the Vim 'e' motion command, allowing users to navigate to the end of the current word, completing the basic word navigation functionality.

  • Implements moveWordEnd utility function with proper Vim semantics
  • Integrates the new motion into the state machine and content script
  • Documents the new keybinding in the README

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/vim-motions.js Implements the core moveWordEnd function and exports it
src/vim-state-machine.js Adds 'e' key binding to trigger moveWordEnd action
src/content.js Imports and maps the moveWordEnd function to the action handler
README.md Documents the new 'e' keybinding for word navigation

Comment on lines +256 to +261
// Skip initial whitespace to mimic Vim's 'e'
while (pos < text.length && isWhitespace(text[pos])) pos++;

if (pos >= text.length) {
setCursorPosition(element, text.length);
return true;
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

The logic for skipping initial whitespace is incorrect for Vim's 'e' motion. In Vim, 'e' moves to the end of the current word if the cursor is within a word, or to the end of the next word if on whitespace. The current implementation always skips whitespace first, which doesn't match Vim behavior when the cursor is already on a word character.

Suggested change
// Skip initial whitespace to mimic Vim's 'e'
while (pos < text.length && isWhitespace(text[pos])) pos++;
if (pos >= text.length) {
setCursorPosition(element, text.length);
return true;
// Determine the character type at the current position
const initialType = getCharType(text[pos]);
if (initialType === 'whitespace') {
// Skip initial whitespace
while (pos < text.length && isWhitespace(text[pos])) pos++;
if (pos >= text.length) {
setCursorPosition(element, text.length);
return true;
}

Copilot uses AI. Check for mistakes.
while (pos < text.length && isWhitespace(text[pos])) pos++;

if (pos >= text.length) {
setCursorPosition(element, text.length);
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

Setting cursor position to text.length may place the cursor beyond the last valid character position. This should be text.length - 1 to position at the last character, or handle the empty text case separately.

Suggested change
setCursorPosition(element, text.length);
setCursorPosition(element, text.length > 0 ? text.length - 1 : 0);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants