feat: enhance AI Chat with context management, file integration, image support, and improved code handling

- Added context tabs system for managing multiple types of context (files, code snippets, images)
   - Added preview functionality for context items
   - Added ability to expand/collapse context previews
   - Added file selection popup/dropdown
   - Added file search functionality
   - Added image upload button
   - Added image paste support
   - Added image preview in context tabs
   - Added automatic code detection on paste
   - Added line number tracking for code snippets
   - Added source file name preservation
   - Added line range display for code contexts
   - Added model selection dropdown (Claude 3.5 Sonnet/Claude 3)
   - Added Ctrl+Enter for sending with full context
   - Added Backspace to remove last context tab when input is empty
   - Added smart code detection on paste
This commit is contained in:
Akhileshrangani4
2024-10-29 01:37:46 -04:00
parent 9c98e41ebb
commit 9c6067dcd9
6 changed files with 665 additions and 83 deletions

View File

@ -172,6 +172,9 @@ export default function CodeEditor({
const editorPanelRef = useRef<ImperativePanelHandle>(null)
const previewWindowRef = useRef<{ refreshIframe: () => void }>(null)
// Ref to store the last copied range in the editor to be used in the AIChat component
const lastCopiedRangeRef = useRef<{ startLine: number; endLine: number } | null>(null);
const debouncedSetIsSelected = useRef(
debounce((value: boolean) => {
setIsSelected(value)
@ -254,6 +257,17 @@ export default function CodeEditor({
updatedOptions
)
}
// Store the last copied range in the editor to be used in the AIChat component
editor.onDidChangeCursorSelection((e) => {
const selection = editor.getSelection();
if (selection) {
lastCopiedRangeRef.current = {
startLine: selection.startLineNumber,
endLine: selection.endLineNumber
};
}
});
}
// Call the function with your file structure
@ -1217,6 +1231,9 @@ export default function CodeEditor({
"No file selected"
}
onClose={toggleAIChat}
editorRef={{ current: editorRef }}
lastCopiedRangeRef={lastCopiedRangeRef}
files={files}
/>
</ResizablePanel>
</>