Spaces:
Runtime error
Runtime error
Thomas G. Lopes
commited on
Commit
·
893f195
1
Parent(s):
43b907b
code snippet insertion
Browse files
src/routes/canvas/chat-node.svelte
CHANGED
|
@@ -146,6 +146,22 @@
|
|
| 146 |
|
| 147 |
const characterCount = $derived(data.query?.length || 0);
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
// Helper function to get actual node dimensions from DOM, converted to flow coordinates
|
| 150 |
function getNodeDimensions(nodeId: string) {
|
| 151 |
const nodeElement = document.querySelector(`[data-id="${nodeId}"]`);
|
|
@@ -292,6 +308,7 @@
|
|
| 292 |
type="button"
|
| 293 |
class="flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-gray-600 transition-colors hover:bg-gray-200 hover:text-gray-900"
|
| 294 |
title="Code snippet"
|
|
|
|
| 295 |
>
|
| 296 |
<IconCode class="h-4 w-4" />
|
| 297 |
</button>
|
|
|
|
| 146 |
|
| 147 |
const characterCount = $derived(data.query?.length || 0);
|
| 148 |
|
| 149 |
+
function insertCodeSnippet() {
|
| 150 |
+
const currentQuery = data.query || "";
|
| 151 |
+
const codeTemplate = "```\n\n```";
|
| 152 |
+
const newQuery = currentQuery + (currentQuery ? "\n\n" : "") + codeTemplate;
|
| 153 |
+
updateNodeData(id, { query: newQuery });
|
| 154 |
+
|
| 155 |
+
setTimeout(() => {
|
| 156 |
+
const textarea = document.getElementById(`message-${id}`) as HTMLTextAreaElement;
|
| 157 |
+
if (textarea) {
|
| 158 |
+
const cursorPosition = newQuery.length - 4;
|
| 159 |
+
textarea.focus();
|
| 160 |
+
textarea.setSelectionRange(cursorPosition, cursorPosition);
|
| 161 |
+
}
|
| 162 |
+
}, 0);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
// Helper function to get actual node dimensions from DOM, converted to flow coordinates
|
| 166 |
function getNodeDimensions(nodeId: string) {
|
| 167 |
const nodeElement = document.querySelector(`[data-id="${nodeId}"]`);
|
|
|
|
| 308 |
type="button"
|
| 309 |
class="flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-gray-600 transition-colors hover:bg-gray-200 hover:text-gray-900"
|
| 310 |
title="Code snippet"
|
| 311 |
+
onclick={insertCodeSnippet}
|
| 312 |
>
|
| 313 |
<IconCode class="h-4 w-4" />
|
| 314 |
</button>
|