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
This commit is contained in:
Robert Clover 2023-02-24 06:15:15 +11:00 committed by GitHub
parent 3f8e09ba3b
commit cb7d1ce509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {