Skip to content

Commit 9f7aeac

Browse files
committed
impr(commandline): when using single list mode, press the up arrow to repeat previous command
1 parent 063a690 commit 9f7aeac

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

frontend/src/ts/commandline/commandline.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let inputModeParams: InputModeParams = {
3434
};
3535
let subgroupOverride: CommandsSubgroup | null = null;
3636
let isAnimating = false;
37+
let lastSingleListModeInputValue = "";
3738

3839
function removeCommandlineBackground(): void {
3940
$("#commandLine").addClass("noBackground");
@@ -509,6 +510,9 @@ async function runActiveCommand(): Promise<void> {
509510
command.exec?.({
510511
commandlineModal: modal,
511512
});
513+
if (Config.singleListCommandLine === "on") {
514+
lastSingleListModeInputValue = inputValue;
515+
}
512516
const isSticky = command.sticky ?? false;
513517
if (!isSticky) {
514518
void AnalyticsController.log("usedCommandLine", { command: command.id });
@@ -574,6 +578,14 @@ function updateInput(setInput?: string): void {
574578
} else {
575579
iconElement.innerHTML = '<i class="fas fa-search"></i>';
576580
element.placeholder = "Search...";
581+
582+
let length = inputValue.length;
583+
if (setInput !== undefined) {
584+
length = setInput.length;
585+
}
586+
setTimeout(() => {
587+
element.setSelectionRange(length, length);
588+
}, 0);
577589
}
578590
}
579591

@@ -631,6 +643,18 @@ const modal = new AnimatedModal({
631643
(e.ctrlKey &&
632644
(e.key.toLowerCase() === "k" || e.key.toLowerCase() === "p"))
633645
) {
646+
if (
647+
Config.singleListCommandLine === "on" &&
648+
inputValue === "" &&
649+
lastSingleListModeInputValue !== ""
650+
) {
651+
inputValue = lastSingleListModeInputValue;
652+
updateInput();
653+
await filterSubgroup();
654+
await showCommands();
655+
await updateActiveCommand();
656+
return;
657+
}
634658
e.preventDefault();
635659
await decrementActiveIndex();
636660
}

0 commit comments

Comments
 (0)