-
Notifications
You must be signed in to change notification settings - Fork 0
Add 'e' motion #10
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
base: main
Are you sure you want to change the base?
Add 'e' motion #10
Conversation
WalkthroughThe 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
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
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🧰 Additional context used🧬 Code Graph Analysis (1)src/content.js (1)
🔇 Additional comments (6)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
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.
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
moveWordEndutility 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 |
| // 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; |
Copilot
AI
Jul 21, 2025
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.
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.
| // 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; | |
| } |
| while (pos < text.length && isWhitespace(text[pos])) pos++; | ||
|
|
||
| if (pos >= text.length) { | ||
| setCursorPosition(element, text.length); |
Copilot
AI
Jul 21, 2025
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.
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.
| setCursorPosition(element, text.length); | |
| setCursorPosition(element, text.length > 0 ? text.length - 1 : 0); |
Summary
moveWordEndutility for moving to the end of a wordeword navigation in READMETesting
npm test(fails: could not read package.json)https://chatgpt.com/codex/tasks/task_e_68675080db58832ebd40f0bd70562420
Summary by CodeRabbit
New Features
Documentation