feat: add shift-to-delete to prompts workspace

This commit adds the Shift key shortcut to the Prompts workspace page to reveal a trash can icon for quick deletion of prompts. This feature is already present for the Models, Tools, and Functions pages.
This commit is contained in:
silentoplayz 2025-08-22 16:09:21 -04:00
parent dafedf5675
commit 9e7ec0eb1e

View file

@ -24,6 +24,9 @@
import Tooltip from '../common/Tooltip.svelte';
import { capitalizeFirstLetter, slugify } from '$lib/utils';
import XMark from '../icons/XMark.svelte';
import GarbageBin from '../icons/GarbageBin.svelte';
let shiftKey = false;
const i18n = getContext('i18n');
let promptsImportInputElement: HTMLInputElement;
@ -89,7 +92,16 @@
const deleteHandler = async (prompt) => {
const command = prompt.command;
await deletePromptByCommand(localStorage.token, command);
const res = await deletePromptByCommand(localStorage.token, command).catch((err) => {
toast.error(err);
return null;
});
if (res) {
toast.success($i18n.t(`Deleted {{name}}`, { name: command }));
}
await init();
};
@ -101,6 +113,32 @@
onMount(async () => {
await init();
loaded = true;
const onKeyDown = (event) => {
if (event.key === 'Shift') {
shiftKey = true;
}
};
const onKeyUp = (event) => {
if (event.key === 'Shift') {
shiftKey = false;
}
};
const onBlur = () => {
shiftKey = false;
};
window.addEventListener('keydown', onKeyDown);
window.addEventListener('keyup', onKeyUp);
window.addEventListener('blur', onBlur);
return () => {
window.removeEventListener('keydown', onKeyDown);
window.removeEventListener('keyup', onKeyUp);
window.removeEventListener('blur', onBlur);
};
});
</script>
@ -202,6 +240,19 @@
</a>
</div>
<div class="flex flex-row gap-0.5 self-center">
{#if shiftKey}
<Tooltip content={$i18n.t('Delete')}>
<button
class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
type="button"
on:click={() => {
deleteHandler(prompt);
}}
>
<GarbageBin />
</button>
</Tooltip>
{:else}
<a
class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
type="button"
@ -246,6 +297,7 @@
<EllipsisHorizontal className="size-5" />
</button>
</PromptMenu>
{/if}
</div>
</div>
{/each}