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 {
|
export function useVimMotions(): VimMotionSystem {
|
||||||
const countRef = useRef<string>('');
|
const countRef = useRef<string>('');
|
||||||
const lastMotionRef = useRef<Motion | null>(null);
|
const lastMotionRef = useRef<Motion | null>(null);
|
||||||
|
const pendingGRef = useRef<boolean>(false);
|
||||||
|
|
||||||
function processKey(key: string): { type: 'move'|'anchor'|'repeat'|'count', data: any } | null {
|
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' && key <= '9') {
|
||||||
if (key === '0' && countRef.current === '') {
|
if (key === '0' && countRef.current === '') {
|
||||||
return { type: 'anchor', data: 'start' };
|
return { type: 'anchor', data: 'start' };
|
||||||
@@ -53,8 +62,8 @@ export function useVimMotions(): VimMotionSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (key === 'g') {
|
if (key === 'g') {
|
||||||
resetCount();
|
pendingGRef.current = true;
|
||||||
return { type: 'anchor', data: 'top' };
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key === 'G') {
|
if (key === 'G') {
|
||||||
|
|||||||
Reference in New Issue
Block a user