From 1f9bcdb0528200029539cf050db87f47dea53617 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 15 Apr 2019 08:41:31 -0700 Subject: [PATCH] Make easter egg handling more efficient --- js/hotkeys.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/js/hotkeys.ts b/js/hotkeys.ts index f6981dc8..635a8096 100644 --- a/js/hotkeys.ts +++ b/js/hotkeys.ts @@ -24,7 +24,7 @@ import { Dispatch } from "./types"; const IGNORE_EVENTS_FROM_TAGS = new Set(["input", "textarea", "select"]); export function bindHotkeys(dispatch: Dispatch): () => void { - let keylog: number[] = []; + let currentPos: number = 0; const trigger = [ 78, // N 85, // U @@ -145,9 +145,8 @@ export function bindHotkeys(dispatch: Dispatch): () => void { // Ignore escape. Usually this gets swallowed by the browser, but not always. if (e.keyCode !== 27) { - keylog.push(e.keyCode); - keylog = keylog.slice(-8); - if (arraysAreEqual(keylog, trigger)) { + currentPos = e.keyCode === trigger[currentPos] ? currentPos + 1 : 0; + if (currentPos === trigger.length) { dispatch({ type: TOGGLE_LLAMA_MODE }); } }