fix: gg now requires two g presses (not just one)
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.
This commit is contained in:
@@ -4,8 +4,17 @@ import type { VimMotionSystem, Motion } from './types';
|
||||
export function useVimMotions(): VimMotionSystem {
|
||||
const countRef = useRef<string>('');
|
||||
const lastMotionRef = useRef<Motion | null>(null);
|
||||
const pendingGRef = useRef<boolean>(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') {
|
||||
|
||||
Reference in New Issue
Block a user