@@ -269,6 +269,8 @@ ${fields}
269
269
document .querySelector (" .loading" ).classList .add (" hidden" )
270
270
}
271
271
}
272
+ const promptSelect = document .getElementById (' prompt-select' );
273
+ const resetButton = document .querySelector (" #prompt-reset" )
272
274
document .querySelector (" form" ).addEventListener (" input" , (e ) => {
273
275
if (e .target .tagName === " SELECT" ) {
274
276
config[e .target .name ] = config .models [e .target .selectedIndex ]
@@ -290,7 +292,7 @@ ${fields}
290
292
socket .emit (' request' , config)
291
293
config .id = null
292
294
loading (config .prompt )
293
- input .textContent = " " ;
295
+ input .textContent = promptSelect . value ;
294
296
}
295
297
});
296
298
input .addEventListener (" keydown" , (e ) => {
@@ -303,9 +305,40 @@ ${fields}
303
305
}
304
306
}
305
307
})
308
+ document .querySelector (" #prompt-cancel" ).addEventListener (" click" , (e ) => {
309
+ e .preventDefault ()
310
+ e .stopPropagation ()
311
+ socket .emit (" request" , {
312
+ prompt: " /stop"
313
+ })
314
+ document .querySelector (" #prompt-run" ).classList .remove (" hidden" )
315
+ document .querySelector (" #prompt-cancel" ).classList .add (" hidden" )
316
+ })
306
317
307
318
// Load prompts from files
308
- const promptSelect = document .getElementById (' prompt-select' );
319
+
320
+ // Update the input text with the selected prompt value
321
+ const handlePromptChange = () => {
322
+ const selectedPromptValue = promptSelect .value ;
323
+ const currentInputValue = input .textContent ;
324
+
325
+ input .textContent = selectedPromptValue;
326
+
327
+ // Move the cursor to the first instance of ">PROMPT" and select only the word ">PROMPT"
328
+ const promptIndex = input .textContent .indexOf (' >PROMPT' );
329
+ if (promptIndex >= 0 ) {
330
+ const range = document .createRange ();
331
+ const selection = window .getSelection ();
332
+ const promptEndIndex = promptIndex + " >PROMPT" .length ;
333
+ range .setStart (input .childNodes [0 ], promptIndex);
334
+ range .setEnd (input .childNodes [0 ], promptEndIndex);
335
+ selection .removeAllRanges ();
336
+ selection .addRange (range);
337
+ }
338
+
339
+ // Focus the input
340
+ input .focus ();
341
+ }
309
342
fetch (' ./prompts' )
310
343
.then (response => response .json ())
311
344
.then (prompts => {
@@ -329,40 +362,7 @@ ${fields}
329
362
promptSelect .value = initialPrompt .value ;
330
363
input .textContent = initialPrompt .value ;
331
364
332
- // Update the input text with the selected prompt value
333
- const handlePromptChange = () => {
334
- const selectedPromptValue = promptSelect .value ;
335
- const currentInputValue = input .textContent ;
336
-
337
- input .textContent = selectedPromptValue;
338
-
339
- // Move the cursor to the first instance of ">PROMPT" and select only the word ">PROMPT"
340
- const promptIndex = input .textContent .indexOf (' >PROMPT' );
341
- if (promptIndex >= 0 ) {
342
- const range = document .createRange ();
343
- const selection = window .getSelection ();
344
- const promptEndIndex = promptIndex + " >PROMPT" .length ;
345
- range .setStart (input .childNodes [0 ], promptIndex);
346
- range .setEnd (input .childNodes [0 ], promptEndIndex);
347
- selection .removeAllRanges ();
348
- selection .addRange (range);
349
- }
350
-
351
- // Focus the input
352
- input .focus ();
353
- }
354
365
promptSelect .addEventListener (' change' , handlePromptChange);
355
-
356
- /*
357
- // Create a Reset button
358
- const resetButton = document.createElement('button');
359
- resetButton.textContent = 'Reset';
360
-
361
- // Append the Reset button to the same container as the dropdown
362
- promptSelect.parentNode.appendChild(resetButton);
363
- */
364
- const resetButton = document .querySelector (" #prompt-reset" )
365
-
366
366
resetButton .addEventListener (' click' , (e ) => {
367
367
e .preventDefault () // Prevent form from submitting
368
368
handlePromptChange ()
0 commit comments