mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 20:31:37 -05:00
Close menu when click outside
This commit is contained in:
@@ -40,7 +40,6 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
|||||||
const [showContextMenu, setShowContextMenu] = useState(false)
|
const [showContextMenu, setShowContextMenu] = useState(false)
|
||||||
const [cursorPosition, setCursorPosition] = useState(0)
|
const [cursorPosition, setCursorPosition] = useState(0)
|
||||||
const [searchQuery, setSearchQuery] = useState("")
|
const [searchQuery, setSearchQuery] = useState("")
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
|
||||||
const textAreaRef = useRef<HTMLTextAreaElement | null>(null)
|
const textAreaRef = useRef<HTMLTextAreaElement | null>(null)
|
||||||
const [isMouseDownOnMenu, setIsMouseDownOnMenu] = useState(false)
|
const [isMouseDownOnMenu, setIsMouseDownOnMenu] = useState(false)
|
||||||
const highlightLayerRef = useRef<HTMLDivElement>(null)
|
const highlightLayerRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -48,6 +47,27 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
|||||||
const [selectedType, setSelectedType] = useState<string | null>(null)
|
const [selectedType, setSelectedType] = useState<string | null>(null)
|
||||||
const [justDeletedSpaceAfterMention, setJustDeletedSpaceAfterMention] = useState(false)
|
const [justDeletedSpaceAfterMention, setJustDeletedSpaceAfterMention] = useState(false)
|
||||||
const [intendedCursorPosition, setIntendedCursorPosition] = useState<number | null>(null)
|
const [intendedCursorPosition, setIntendedCursorPosition] = useState<number | null>(null)
|
||||||
|
const contextMenuContainerRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (
|
||||||
|
contextMenuContainerRef.current &&
|
||||||
|
!contextMenuContainerRef.current.contains(event.target as Node)
|
||||||
|
) {
|
||||||
|
setShowContextMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showContextMenu) {
|
||||||
|
document.addEventListener("mousedown", handleClickOutside)
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("mousedown", handleClickOutside)
|
||||||
|
}
|
||||||
|
}, [showContextMenu, setShowContextMenu])
|
||||||
|
|
||||||
const handleMentionSelect = useCallback(
|
const handleMentionSelect = useCallback(
|
||||||
(type: string, value: string) => {
|
(type: string, value: string) => {
|
||||||
if (value === "File" || value === "Folder") {
|
if (value === "File" || value === "Folder") {
|
||||||
@@ -297,7 +317,6 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
|
||||||
style={{
|
style={{
|
||||||
padding: "10px 15px",
|
padding: "10px 15px",
|
||||||
opacity: textAreaDisabled ? 0.5 : 1,
|
opacity: textAreaDisabled ? 0.5 : 1,
|
||||||
@@ -305,15 +324,16 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
}}>
|
}}>
|
||||||
{showContextMenu && (
|
{showContextMenu && (
|
||||||
<ContextMenu
|
<div ref={contextMenuContainerRef}>
|
||||||
containerWidth={containerRef.current?.clientWidth || 0}
|
<ContextMenu
|
||||||
onSelect={handleMentionSelect}
|
onSelect={handleMentionSelect}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
onMouseDown={handleMenuMouseDown}
|
onMouseDown={handleMenuMouseDown}
|
||||||
selectedIndex={selectedMenuIndex}
|
selectedIndex={selectedMenuIndex}
|
||||||
setSelectedIndex={setSelectedMenuIndex}
|
setSelectedIndex={setSelectedMenuIndex}
|
||||||
selectedType={selectedType}
|
selectedType={selectedType}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isTextAreaFocused && (
|
{!isTextAreaFocused && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React, { useEffect, useState, useRef } from "react"
|
|||||||
import { getContextMenuOptions } from "../utils/mention-context"
|
import { getContextMenuOptions } from "../utils/mention-context"
|
||||||
|
|
||||||
interface ContextMenuProps {
|
interface ContextMenuProps {
|
||||||
containerWidth: number
|
|
||||||
onSelect: (type: string, value: string) => void
|
onSelect: (type: string, value: string) => void
|
||||||
searchQuery: string
|
searchQuery: string
|
||||||
onMouseDown: () => void
|
onMouseDown: () => void
|
||||||
@@ -12,7 +11,6 @@ interface ContextMenuProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ContextMenu: React.FC<ContextMenuProps> = ({
|
const ContextMenu: React.FC<ContextMenuProps> = ({
|
||||||
containerWidth,
|
|
||||||
onSelect,
|
onSelect,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
onMouseDown,
|
onMouseDown,
|
||||||
|
|||||||
Reference in New Issue
Block a user