From 5bbb6a62a426e144fcc82dc9b8dba03f18365c68 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 28 Jun 2022 17:57:10 +0200 Subject: [PATCH] improved quick restart esc pressing tab now opens the command line you can still insert tab as character (shift tab to open the commandline if text has tab) closes #3233 --- .../src/ts/controllers/input-controller.ts | 16 +++++++++++++++- frontend/src/ts/elements/commandline.ts | 18 +++++++++++++++--- frontend/src/ts/elements/modes-notice.ts | 12 +++++++++--- frontend/src/ts/test/test-logic.ts | 8 ++++++-- frontend/src/ts/ui.ts | 2 +- frontend/static/html/pages/settings.html | 10 +++++----- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts index adee497d0..88d907b5f 100644 --- a/frontend/src/ts/controllers/input-controller.ts +++ b/frontend/src/ts/controllers/input-controller.ts @@ -611,7 +611,21 @@ function handleTab(event: JQuery.KeyDownEvent, popupVisible: boolean): void { const modalVisible = !$("#commandLineWrapper").hasClass("hidden") || popupVisible; - if (Config.quickRestart === "tab") { + if (Config.quickRestart === "esc") { + // dont do anything special + if (modalVisible) return; + + // dont do anything on login so we can tab/esc betweeen inputs + if (ActivePage.get() === "login") return; + + event.preventDefault(); + // insert tab character if needed (only during the test) + if (!TestUI.resultVisible && shouldInsertTabCharacter) { + handleChar("\t", TestInput.input.current.length); + setWordsInput(" " + TestInput.input.current); + return; + } + } else if (Config.quickRestart === "tab") { // dont do anything special if (modalVisible) return; diff --git a/frontend/src/ts/elements/commandline.ts b/frontend/src/ts/elements/commandline.ts index 351d48cee..634375ea8 100644 --- a/frontend/src/ts/elements/commandline.ts +++ b/frontend/src/ts/elements/commandline.ts @@ -7,6 +7,8 @@ import * as DB from "../db"; import * as Notifications from "../elements/notifications"; import * as AnalyticsController from "../controllers/analytics-controller"; import * as PageTransition from "../states/page-transition"; +import * as TestWords from "../test/test-words"; +import * as ActivePage from "../states/active-page"; import { Auth } from "../firebase"; import { isAnyPopupVisible } from "../utils/misc"; @@ -389,7 +391,8 @@ $(document).ready(() => { if (PageTransition.get()) return event.preventDefault(); // opens command line if escape or ctrl/cmd + shift + p if ( - event.key === "Escape" && + ((event.key === "Escape" && Config.quickRestart !== "esc") || + (event.key === "Tab" && Config.quickRestart === "esc")) && !$("#commandLineWrapper").hasClass("hidden") ) { if (CommandlineLists.current.length > 1) { @@ -404,17 +407,26 @@ $(document).ready(() => { } if ( (event.key === "Escape" && Config.quickRestart !== "esc") || + (event.key === "Tab" && + Config.quickRestart === "esc" && + !TestWords.hasTab && + !event.shiftKey) || + (event.key === "Tab" && + Config.quickRestart === "esc" && + TestWords.hasTab && + event.shiftKey) || (event.key && event.key.toLowerCase() === "p" && (event.metaKey || event.ctrlKey) && event.shiftKey) ) { - event.preventDefault(); - const popupVisible = isAnyPopupVisible(); if (popupVisible) return; + if (Config.quickRestart === "esc" && ActivePage.get() === "login") return; + event.preventDefault(); + if (Config.singleListCommandLine == "on") { useSingleListCommandLine(false); } else { diff --git a/frontend/src/ts/elements/modes-notice.ts b/frontend/src/ts/elements/modes-notice.ts index 202483ff5..04bbb9fe7 100644 --- a/frontend/src/ts/elements/modes-notice.ts +++ b/frontend/src/ts/elements/modes-notice.ts @@ -40,9 +40,15 @@ export async function update(): Promise { } if (TestWords.hasTab) { - $(".pageTest #testModesNotice").append( - `
shift + tab to restart
` - ); + if (Config.quickRestart === "esc") { + $(".pageTest #testModesNotice").append( + `
shift + tab to open commandline
` + ); + } else { + $(".pageTest #testModesNotice").append( + `
shift + tab to restart
` + ); + } } if (TestState.activeChallenge) { diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index df2cf7b20..6d4271e67 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -322,8 +322,12 @@ export function restart( } if (ActivePage.get() == "test" && !TestUI.resultVisible) { if (!ManualRestart.get()) { - if (TestWords.hasTab) { - if (!event?.shiftKey) return; + if ( + TestWords.hasTab && + !event?.shiftKey && + Config.quickRestart !== "esc" + ) { + return; } if (Config.mode !== "zen") event?.preventDefault(); if ( diff --git a/frontend/src/ts/ui.ts b/frontend/src/ts/ui.ts index 561bf3887..df36e252d 100644 --- a/frontend/src/ts/ui.ts +++ b/frontend/src/ts/ui.ts @@ -22,7 +22,7 @@ export function updateKeytips(): void { if (Config.quickRestart === "esc") { $("#bottom .keyTips").html(` esc - restart test
- ctrl/cmd+shift+p - command line`); + tab or ctrl/cmd+shift+p - command line`); } else if (Config.quickRestart === "tab") { $("#bottom .keyTips").html(` tab - restart test
diff --git a/frontend/static/html/pages/settings.html b/frontend/static/html/pages/settings.html index 816a25865..23f3f912f 100644 --- a/frontend/static/html/pages/settings.html +++ b/frontend/static/html/pages/settings.html @@ -168,11 +168,11 @@ tab or esc - to quickly restart the test, or to quickly jump to the test page. The - "tab" setting disables tab navigation on the website, while the "esc" - disables opening the command line with - esc - . + to quickly restart the test, or to quickly jump to the test page. Both + options disable tab navigation on most parts of the website. Using the + "esc" option will move opening the commandline to the + tab + key.