impr(commandline): when using single list mode, press the up arrow to repeat previous command

This commit is contained in:
Miodec 2024-10-16 14:28:49 +02:00
parent 063a6901a6
commit 9f7aeac5af

View file

@ -34,6 +34,7 @@ let inputModeParams: InputModeParams = {
};
let subgroupOverride: CommandsSubgroup | null = null;
let isAnimating = false;
let lastSingleListModeInputValue = "";
function removeCommandlineBackground(): void {
$("#commandLine").addClass("noBackground");
@ -509,6 +510,9 @@ async function runActiveCommand(): Promise<void> {
command.exec?.({
commandlineModal: modal,
});
if (Config.singleListCommandLine === "on") {
lastSingleListModeInputValue = inputValue;
}
const isSticky = command.sticky ?? false;
if (!isSticky) {
void AnalyticsController.log("usedCommandLine", { command: command.id });
@ -574,6 +578,14 @@ function updateInput(setInput?: string): void {
} else {
iconElement.innerHTML = '<i class="fas fa-search"></i>';
element.placeholder = "Search...";
let length = inputValue.length;
if (setInput !== undefined) {
length = setInput.length;
}
setTimeout(() => {
element.setSelectionRange(length, length);
}, 0);
}
}
@ -631,6 +643,18 @@ const modal = new AnimatedModal({
(e.ctrlKey &&
(e.key.toLowerCase() === "k" || e.key.toLowerCase() === "p"))
) {
if (
Config.singleListCommandLine === "on" &&
inputValue === "" &&
lastSingleListModeInputValue !== ""
) {
inputValue = lastSingleListModeInputValue;
updateInput();
await filterSubgroup();
await showCommands();
await updateActiveCommand();
return;
}
e.preventDefault();
await decrementActiveIndex();
}