@@ -315,6 +325,52 @@
userMessageElement.scrollIntoView({ block: 'center' });
editButton?.click();
}
+
+ if (prompt.charAt(0) === '/' && e.key === 'Tab') {
+ e.preventDefault();
+
+ const commandOptionButton = [
+ ...document.getElementsByClassName('selected-command-option-button')
+ ]?.at(-1);
+
+ commandOptionButton?.click();
+ }
+
+ if (prompt.charAt(0) === '/' && e.key === 'ArrowUp') {
+ promptsElement.selectUp();
+
+ const commandOptionButton = [
+ ...document.getElementsByClassName('selected-command-option-button')
+ ]?.at(-1);
+ commandOptionButton.scrollIntoView({ block: 'center' });
+ }
+
+ if (prompt.charAt(0) === '/' && e.key === 'ArrowDown') {
+ promptsElement.selectDown();
+
+ const commandOptionButton = [
+ ...document.getElementsByClassName('selected-command-option-button')
+ ]?.at(-1);
+ commandOptionButton.scrollIntoView({ block: 'center' });
+ }
+
+ if (prompt.charAt(0) === '/' && e.key === 'Enter') {
+ e.preventDefault();
+
+ const commandOptionButton = [
+ ...document.getElementsByClassName('selected-command-option-button')
+ ]?.at(-1);
+
+ commandOptionButton?.click();
+ }
+
+ const words = findWordIndices(prompt);
+
+ if (words.length > 0 && e.key === 'Tab') {
+ const word = words.at(0);
+ e.preventDefault();
+ e.target.setSelectionRange(word?.startIndex, word.endIndex + 1);
+ }
}}
rows="1"
on:input={(e) => {
diff --git a/src/lib/components/chat/MessageInput/PromptCommands.svelte b/src/lib/components/chat/MessageInput/PromptCommands.svelte
new file mode 100644
index 000000000..91e5f1aa4
--- /dev/null
+++ b/src/lib/components/chat/MessageInput/PromptCommands.svelte
@@ -0,0 +1,121 @@
+
+
+{#if filteredPromptCommands.length > 0}
+
+
+
+
+ {#each filteredPromptCommands as command, commandIdx}
+
+ {/each}
+
+
+
+{/if}
diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts
index 8f7e711bf..344672da5 100644
--- a/src/lib/utils/index.ts
+++ b/src/lib/utils/index.ts
@@ -111,3 +111,19 @@ export const checkVersion = (required, current) => {
caseFirst: 'upper'
}) < 0;
};
+
+export const findWordIndices = (text) => {
+ const regex = /\[([^\]]+)\]/g;
+ let matches = [];
+ let match;
+
+ while ((match = regex.exec(text)) !== null) {
+ matches.push({
+ word: match[1],
+ startIndex: match.index,
+ endIndex: regex.lastIndex - 1
+ });
+ }
+
+ return matches;
+};