Add problems option to context menu

This commit is contained in:
Saoud Rizwan
2024-09-17 15:21:36 -04:00
parent d47008f0b4
commit 7e91e7aecb
3 changed files with 42 additions and 10 deletions

View File

@@ -87,6 +87,9 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
} else if (type === "file" || type === "folder") {
// For files and folders, we insert the path
insertValue = value
} else if (type === "problems") {
// For workspace problems, we insert @problems
insertValue = "problems"
}
const newValue = insertMention(textAreaRef.current.value, cursorPosition, insertValue)
@@ -105,6 +108,12 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
const handleKeyDown = useCallback(
(event: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (showContextMenu) {
if (event.key === "Escape") {
// event.preventDefault()
setShowContextMenu(false)
return
}
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
event.preventDefault()
setSelectedMenuIndex((prevIndex) => {
@@ -159,7 +168,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
charAfterCursor === " " || charAfterCursor === "\n" || charAfterCursor === "\r\n"
if (
charBeforeIsWhitespace &&
inputValue.slice(0, cursorPosition - 1).match(/@(\/|\w+:\/\/)[^\s]+$/)
inputValue.slice(0, cursorPosition - 1).match(/@((?:\/|\w+:\/\/)[^\s]+|problems)$/)
) {
const newCursorPosition = cursorPosition - 1
if (!charAfterIsWhitespace) {
@@ -220,7 +229,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
if (query.length > 0) {
setSelectedMenuIndex(0)
} else {
setSelectedMenuIndex(2) // Set to "File" option by default
setSelectedMenuIndex(3) // Set to "File" option by default
}
} else {
setSearchQuery("")
@@ -230,6 +239,12 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
[setInputValue]
)
useEffect(() => {
if (!showContextMenu) {
setSelectedType(null)
}
}, [showContextMenu])
const handleBlur = useCallback(() => {
// Only hide the context menu if the user didn't click on it
if (!isMouseDownOnMenu) {
@@ -299,7 +314,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
if (!textAreaRef.current || !highlightLayerRef.current) return
const text = textAreaRef.current.value
const mentionRegex = /@(\/|\w+:\/\/)[^\s]+/g
const mentionRegex = /@((?:\/|\w+:\/\/)[^\s]+|problems\b)/g
highlightLayerRef.current.innerHTML = text
.replace(/\n$/, "\n\n")

View File

@@ -88,6 +88,8 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
? "Add file"
: option.value === "Folder"
? "Add folder"
: option.value === "Problems"
? "Workspace Problems"
: option.value === "URL"
? "Paste URL to scrape"
: option.value}
@@ -95,11 +97,12 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
{(option.value === "File" || option.value === "Folder") && (
<i className="codicon codicon-chevron-right" style={{ fontSize: "14px" }} />
)}
{(option.type === "file" || option.type === "folder") &&
option.value !== "File" &&
option.value !== "Folder" && (
<i className="codicon codicon-add" style={{ fontSize: "14px" }} />
)}
{(option.type === "problems" ||
((option.type === "file" || option.type === "folder") &&
option.value !== "File" &&
option.value !== "Folder")) && (
<i className="codicon codicon-add" style={{ fontSize: "14px" }} />
)}
</div>
))}
</div>