Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
weilirs committed Nov 20, 2024
1 parent b13d21e commit d5f509a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 43 deletions.
37 changes: 2 additions & 35 deletions src/components/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,17 @@ const ChatInput: React.FC<ChatInputProps> = ({
const [searchTerm, setSearchTerm] = useState('')
const textareaRef = useRef<HTMLTextAreaElement>(null)

const getCaretCoordinates = (element: HTMLTextAreaElement) => {
const { selectionStart, value } = element
const textBeforeCaret = value.substring(0, selectionStart)

// Create a hidden div with the same styling as textarea
const mirror = document.createElement('div')
mirror.style.cssText = window.getComputedStyle(element).cssText
mirror.style.height = 'auto'
mirror.style.position = 'absolute'
mirror.style.visibility = 'hidden'
mirror.style.whiteSpace = 'pre-wrap'
document.body.appendChild(mirror)

// Create a span for the text before caret
const textNode = document.createTextNode(textBeforeCaret)
const span = document.createElement('span')
span.appendChild(textNode)
mirror.appendChild(span)

// Get coordinates
const coordinates = {
top: span.offsetTop + parseInt(window.getComputedStyle(element).lineHeight, 10) / 2,
left: span.offsetLeft,
}

// Clean up
document.body.removeChild(mirror)

return coordinates
}

const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (userTextFieldInput && !e.shiftKey && e.key === 'Enter') {
e.preventDefault()
handleSubmitNewMessage()
} else if (e.key === '@') {
const rect = e.currentTarget.getBoundingClientRect()
const position = getCaretCoordinates(e.currentTarget)
setAutocompletePosition({
top: rect.top + position.top,
left: rect.left + position.left,
top: rect.top,
left: rect.left,
})
setShowFileAutocomplete(true)
// console.log('showFileAutocomplete', showFileAutocomplete)
} else if (showFileAutocomplete && e.key === 'Escape') {
setShowFileAutocomplete(false)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Chat/MessageComponents/ChatSources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const ChatSources: React.FC<ChatSourcesProps> = ({ contextItems }) => {
return (
<div>
<div className="mb-1 text-sm text-muted-foreground">Sources:</div>

<div className="flex space-x-2 overflow-x-auto p-0 pb-1 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-gray-800">
{/* eslint-disable-next-line tailwindcss/no-custom-classname */}
<div className="scrollbar-thumb-rounded-full flex space-x-2 overflow-x-auto p-0 pb-1 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-gray-800">
{contextItems.map((contextItem) => (
<HoverCard key={getItemPath(contextItem)} openDelay={600}>
<HoverCardTrigger>
Expand Down
6 changes: 0 additions & 6 deletions src/components/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ const ChatComponent: React.FC = () => {
return
}

// Extract file references from the message
const fileRefs = await extractFileReferences(userTextFieldInput || '')
// console.log('fileRefs', fileRefs)

// Create or update chat with file context
outputChat = userTextFieldInput?.trim()
Expand All @@ -68,14 +66,10 @@ const ChatComponent: React.FC = () => {
files: fileRefs,
})
: chat
// outputChat = userTextFieldInput?.trim()
// ? await appendToOrCreateChat(chat, userTextFieldInput, agentConfig)
// : chat

if (!outputChat) {
return
}
// console.log('outputChat', outputChat)
setCurrentChat(outputChat)
await saveChat(outputChat)

Expand Down

0 comments on commit d5f509a

Please sign in to comment.