From 7c7a80c450df2b2cd212ce7db0960bab685b6591 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 17 Feb 2024 23:28:07 -0800 Subject: [PATCH] feat: CLIPBOARD variable for prompt preset --- .../chat/MessageInput/PromptCommands.svelte | 14 +++++++++++++- src/routes/(app)/prompts/create/+page.svelte | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/lib/components/chat/MessageInput/PromptCommands.svelte b/src/lib/components/chat/MessageInput/PromptCommands.svelte index 83e385612..04fb4c925 100644 --- a/src/lib/components/chat/MessageInput/PromptCommands.svelte +++ b/src/lib/components/chat/MessageInput/PromptCommands.svelte @@ -2,6 +2,7 @@ import { prompts } from '$lib/stores'; import { findWordIndices } from '$lib/utils'; import { tick } from 'svelte'; + import toast from 'svelte-french-toast'; export let prompt = ''; let selectedCommandIdx = 0; @@ -24,7 +25,18 @@ }; const confirmCommand = async (command) => { - prompt = command.content; + let text = command.content; + + if (command.content.includes('{{CLIPBOARD}}')) { + const clipboardText = await navigator.clipboard.readText().catch((err) => { + toast.error('Failed to read clipboard contents'); + return '{{CLIPBOARD}}'; + }); + + text = command.content.replaceAll('{{CLIPBOARD}}', clipboardText); + } + + prompt = text; const chatInputElement = document.getElementById('chat-textarea'); diff --git a/src/routes/(app)/prompts/create/+page.svelte b/src/routes/(app)/prompts/create/+page.svelte index 083c9c358..9a85046ad 100644 --- a/src/routes/(app)/prompts/create/+page.svelte +++ b/src/routes/(app)/prompts/create/+page.svelte @@ -171,12 +171,18 @@
- Format your variables using square brackets like this: [variable] . Make sure to enclose them with '[' - and ']' . + and ']'. +
+ +
+ Utilize {`{{CLIPBOARD}}`} variable to have them replaced with clipboard content.