From c187ff455e21d23cbbc0003d4f574b57e650fc13 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Wed, 22 Oct 2025 19:17:14 +0100 Subject: [PATCH] fix: gg now requires two g presses (not just one) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added pendingGRef to track when waiting for second 'g': - First g: Set pendingGRef = true, return null (no action) - Second g: Check pendingGRef, if true → 'top' anchor - Any other key after first g: Clear pendingGRef, return null Now: - g alone → Nothing (waiting for second g) - gg → Jump to top of column - G → Jump to bottom of column Matches vim behavior for gg command. --- src/useCursor/useVimMotions.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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') {