0 works both ways now
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user