Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

- `w` - Jump forward to the start of the next word
- `b` - Jump backward to the start of the previous word
- `e` - Jump to the end of the current word

**Editing Commands:**

Expand Down
2 changes: 2 additions & 0 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
moveDown,
moveWordForward,
moveWordBackward,
moveWordEnd,
deleteText,
deleteWord,
changeWord
Expand Down Expand Up @@ -332,6 +333,7 @@
'moveDown': () => moveDown(element),
'moveWordForward': () => moveWordForward(element),
'moveWordBackward': () => moveWordBackward(element),
'moveWordEnd': () => moveWordEnd(element),
'deleteWord': () => deleteWord(element),
'changeWord': () => changeWord(element)
};
Expand Down
27 changes: 27 additions & 0 deletions src/vim-motions.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,32 @@
return true;
};

const moveWordEnd = (element) => {
let pos = getCursorPosition(element);
const text = getText(element);

if (pos >= text.length) return false;

// Skip initial whitespace to mimic Vim's 'e'
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.
return true;
Comment on lines +256 to +261
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.
}

const targetType = getCharType(text[pos]);

if (targetType === 'word') {
while (pos < text.length - 1 && isWordChar(text[pos + 1])) pos++;
} else if (targetType === 'punctuation') {
while (pos < text.length - 1 && isPunctuation(text[pos + 1])) pos++;
}

setCursorPosition(element, pos);
return true;
};

// --- Text Modification Functions ---

/**
Expand Down Expand Up @@ -472,6 +498,7 @@
moveDown,
moveWordForward,
moveWordBackward,
moveWordEnd,
deleteText,
deleteWord,
changeWord
Expand Down
1 change: 1 addition & 0 deletions src/vim-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'l': 'moveRight',
'w': 'moveWordForward',
'b': 'moveWordBackward',
'e': 'moveWordEnd',
'arrowleft': 'moveLeft',
'arrowdown': 'moveDown',
'arrowup': 'moveUp',
Expand Down