diff --git a/src/useCursor/useVimMotions.ts b/src/useCursor/useVimMotions.ts index 16e6dab..d8cde02 100644 --- a/src/useCursor/useVimMotions.ts +++ b/src/useCursor/useVimMotions.ts @@ -4,8 +4,17 @@ import type { VimMotionSystem, Motion } from './types'; export function useVimMotions(): VimMotionSystem { const countRef = useRef(''); const lastMotionRef = useRef(null); + const pendingGRef = useRef(false); function processKey(key: string): { type: 'move'|'anchor'|'repeat'|'count', data: any } | null { + if (pendingGRef.current) { + pendingGRef.current = false; + if (key === 'g') { + resetCount(); + return { type: 'anchor', data: 'top' }; + } + return null; + } if (key >= '0' && key <= '9') { if (key === '0' && countRef.current === '') { return { type: 'anchor', data: 'start' }; @@ -53,8 +62,8 @@ export function useVimMotions(): VimMotionSystem { } if (key === 'g') { - resetCount(); - return { type: 'anchor', data: 'top' }; + pendingGRef.current = true; + return null; } if (key === 'G') {