From cb7d1ce5092d7258fd5dd610dc68277f0340195f Mon Sep 17 00:00:00 2001 From: Robert Clover Date: Fri, 24 Feb 2023 06:15:15 +1100 Subject: [PATCH] feat: support Emacs/Vim navigation in command line (#4019) clo4 * feat: support ctrl-n/p/j/k in command line This allows for both emacs and vim style navigation, which is muscle memory for a lot of people but currently unsupported in the main list view people use. Supporting both feels a lot more natural, and makes navigation easier for people that either don't have arrow keys at all or on their main layer * fix comment * flip conditions to check ctrl first This is more likely to short circuit faster because ctrl isn't the common case --- frontend/src/ts/commandline/index.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/ts/commandline/index.ts b/frontend/src/ts/commandline/index.ts index 77a0207e0..bf01fff3a 100644 --- a/frontend/src/ts/commandline/index.ts +++ b/frontend/src/ts/commandline/index.ts @@ -669,7 +669,14 @@ $(document).on("keydown", (e) => { trigger(command); return; } - if (e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "Tab") { + if ( + e.key === "ArrowUp" || + e.key === "ArrowDown" || + e.key === "Tab" || + // Should only branch if ctrl is held to allow the letters to still be typed + (e.ctrlKey && + (e.key === "p" || e.key === "n" || e.key === "j" || e.key === "k")) + ) { e.preventDefault(); $("#commandLineWrapper #commandLine .suggestions .entry").unbind( "mouseenter mouseleave" @@ -682,7 +689,10 @@ $(document).on("keydown", (e) => { }); if ( e.key === "ArrowUp" || - (e.key === "Tab" && e.shiftKey && Config.quickRestart !== "esc") + (e.key === "Tab" && e.shiftKey && Config.quickRestart !== "esc") || + // Don't need to check for ctrl because that was already done above + e.key === "p" || + e.key === "k" ) { entries.removeClass("activeKeyboard"); if (activenum == 0) { @@ -695,7 +705,9 @@ $(document).on("keydown", (e) => { } if ( e.key === "ArrowDown" || - (e.key === "Tab" && !e.shiftKey && Config.quickRestart !== "esc") + (e.key === "Tab" && !e.shiftKey && Config.quickRestart !== "esc") || + e.key === "n" || + e.key === "j" ) { entries.removeClass("activeKeyboard"); if (activenum + 1 == entries.length) {