0 works both ways now

This commit is contained in:
2025-10-19 15:09:41 +01:00
parent 47aea08d49
commit 07f218f4dd
4 changed files with 99 additions and 89 deletions
+1
View File
@@ -92,6 +92,7 @@ export type CursorManager = {
repeatLastMotion: () => void;
resetCount: () => void;
getCount: () => string;
hasCount: () => boolean;
setCount: (digit: string) => void;
setLastKey: (key: string) => void;
getLastKey: () => string;
+5
View File
@@ -160,6 +160,10 @@ export function useCursor(board: BoardManager, gameStatusManager: GameStatusMana
return String(vimMotions.getCount());
}
function hasCount(): boolean {
return vimMotions.hasCount();
}
function setCount(digit: string): void {
vimMotions.processKey(digit);
}
@@ -187,6 +191,7 @@ export function useCursor(board: BoardManager, gameStatusManager: GameStatusMana
repeatLastMotion,
resetCount,
getCount,
hasCount,
setCount,
setLastKey,
getLastKey,
+1 -3
View File
@@ -34,8 +34,7 @@ export const useGameKeys = (props: UseGameKeysParams) => {
const handler = (ev: KeyboardEvent) => {
if (["waiting", "game-over", "game-won"].includes(gameStatus)) return;
// "0" behaves like Vim: beginning of line
if (ev.key === "0" && cursor.getCount() === "") {
if (ev.key === "0" && !cursor.hasCount()) {
recordKey("0");
cursor.resetCount();
cursor.moveToStart();
@@ -44,7 +43,6 @@ export const useGameKeys = (props: UseGameKeysParams) => {
const isDigit = ev.key >= "0" && ev.key <= "9";
if (isDigit) {
if (ev.key === "0" && cursor.getCount() === "") return;
recordKey(ev.key);
cursor.setCount(ev.key);
return;
+6
View File
@@ -6,6 +6,7 @@ export type VimMotionSystem = {
processKey: (key: string) => { type: 'move'|'anchor'|'repeat'|'count', data: any } | null;
resetCount: () => void;
getCount: () => number;
hasCount: () => boolean;
setLastMotion: (motion: Motion) => void;
repeatLastMotion: () => Motion | null;
};
@@ -98,10 +99,15 @@ export function useVimMotions(): VimMotionSystem {
return lastMotionRef.current;
}
function hasCount(): boolean {
return countRef.current !== '';
}
return {
processKey,
resetCount,
getCount,
hasCount,
setLastMotion,
repeatLastMotion
};