Update main.js
Browse files
main.js
CHANGED
@@ -112,9 +112,20 @@ async function sendPrompt() {
|
|
112 |
});
|
113 |
|
114 |
const data = await response.json();
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
$('#status').text('Ready');
|
|
|
118 |
}
|
119 |
|
120 |
// Add this function to handle right-click context menu
|
|
|
112 |
});
|
113 |
|
114 |
const data = await response.json();
|
115 |
+
// Check if context is empty
|
116 |
+
if (context.trim() === '') {
|
117 |
+
// If context is empty, set the entire editor value
|
118 |
+
editor.setValue(data.response);
|
119 |
+
} else {
|
120 |
+
// Get the current selection range in the editor
|
121 |
+
const selectionStart = editor.getSelectionStart(); // Get start index of selection
|
122 |
+
const selectionEnd = editor.getSelectionEnd(); // Get end index of selection
|
123 |
+
|
124 |
+
// Replace only the highlighted text with the model's response
|
125 |
+
editor.replaceRange(data.response, selectionStart, selectionEnd);
|
126 |
+
}
|
127 |
$('#status').text('Ready');
|
128 |
+
$('#loadingSpinner').hide();
|
129 |
}
|
130 |
|
131 |
// Add this function to handle right-click context menu
|