feat(cli): Add W, B, E Vim motions and operator support (#16209)

Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
Adam DeMuri
2026-02-05 10:29:30 -07:00
committed by GitHub
parent 1cae5ab158
commit ee2c8eef19
6 changed files with 836 additions and 82 deletions

View File

@@ -27,6 +27,9 @@ import {
textBufferReducer,
findWordEndInLine,
findNextWordStartInLine,
findNextBigWordStartInLine,
findPrevBigWordStartInLine,
findBigWordEndInLine,
isWordCharStrict,
calculateTransformationsForLine,
calculateTransformedLine,
@@ -87,6 +90,43 @@ describe('textBufferReducer', () => {
expect(state).toEqual(initialState);
});
describe('Big Word Navigation Helpers', () => {
describe('findNextBigWordStartInLine (W)', () => {
it('should skip non-whitespace and then whitespace', () => {
expect(findNextBigWordStartInLine('hello world', 0)).toBe(6);
expect(findNextBigWordStartInLine('hello.world test', 0)).toBe(12);
expect(findNextBigWordStartInLine(' test', 0)).toBe(3);
expect(findNextBigWordStartInLine('test ', 0)).toBe(null);
});
});
describe('findPrevBigWordStartInLine (B)', () => {
it('should skip whitespace backwards then non-whitespace', () => {
expect(findPrevBigWordStartInLine('hello world', 6)).toBe(0);
expect(findPrevBigWordStartInLine('hello.world test', 12)).toBe(0);
expect(findPrevBigWordStartInLine(' test', 3)).toBe(null); // At start of word
expect(findPrevBigWordStartInLine(' test', 4)).toBe(3); // Inside word
expect(findPrevBigWordStartInLine('test ', 6)).toBe(0);
});
});
describe('findBigWordEndInLine (E)', () => {
it('should find end of current big word', () => {
expect(findBigWordEndInLine('hello world', 0)).toBe(4);
expect(findBigWordEndInLine('hello.world test', 0)).toBe(10);
expect(findBigWordEndInLine('hello.world test', 11)).toBe(15);
});
it('should skip whitespace if currently on whitespace', () => {
expect(findBigWordEndInLine('hello world', 5)).toBe(12);
});
it('should find next big word end if at end of current', () => {
expect(findBigWordEndInLine('hello world', 4)).toBe(10);
});
});
});
describe('set_text action', () => {
it('should set new text and move cursor to the end', () => {
const action: TextBufferAction = {