@@ -24,6 +24,8 @@ interface ChatHistoryTreeNodeProps {
2424 onCreate ?: ( type : 'folder' | 'chat' ) => void
2525 onChatClick ?: ( chatId : string ) => void
2626 onSaveEdit ?: ( nodeId : string , nodeType : 'folder' | 'chat' , newValue : string ) => void
27+ onStartEdit ?: ( ) => void
28+ onEndEdit ?: ( ) => void
2729}
2830
2931export default function ChatHistoryTreeNode ( {
@@ -34,7 +36,9 @@ export default function ChatHistoryTreeNode({
3436 onDelete,
3537 onCreate,
3638 onChatClick,
37- onSaveEdit
39+ onSaveEdit,
40+ onStartEdit,
41+ onEndEdit
3842} : ChatHistoryTreeNodeProps ) {
3943 const [ isHovered , setIsHovered ] = useState ( false )
4044 const [ isInlineEditing , setIsInlineEditing ] = useState ( false )
@@ -56,18 +60,21 @@ export default function ChatHistoryTreeNode({
5660 const currentName = getName ( )
5761 setEditValue ( currentName )
5862 setIsInlineEditing ( true )
63+ onStartEdit ?.( )
5964 }
6065
6166 const handleSaveEdit = ( ) => {
6267 if ( editValue . trim ( ) && onSaveEdit ) {
6368 onSaveEdit ( data . id , type , editValue . trim ( ) )
6469 }
6570 setIsInlineEditing ( false )
71+ onEndEdit ?.( )
6672 }
6773
6874 const handleCancelEdit = ( ) => {
6975 setIsInlineEditing ( false )
7076 setEditValue ( '' )
77+ onEndEdit ?.( )
7178 }
7279
7380 const handleKeyDown = ( e : React . KeyboardEvent ) => {
@@ -187,6 +194,13 @@ export default function ChatHistoryTreeNode({
187194 onMouseLeave = { ( ) => setIsHovered ( false ) }
188195 onClick = { handleClick }
189196 onDoubleClick = { handleDoubleClick }
197+ draggable = { false }
198+ onMouseDown = { ( e ) => {
199+ // 阻止编辑状态下的拖动
200+ if ( isInlineEditing ) {
201+ e . stopPropagation ( )
202+ }
203+ } }
190204 >
191205 < div className = "tree-node-content" >
192206 < div className = "tree-node-icon" > { getIcon ( ) } </ div >
@@ -201,8 +215,12 @@ export default function ChatHistoryTreeNode({
201215 size = "small"
202216 value = { editValue }
203217 onChange = { ( e ) => setEditValue ( e . target . value ) }
204- onBlur = { handleSaveEdit }
218+ onBlur = { ( e ) => {
219+ handleSaveEdit ( )
220+ } }
205221 onKeyDown = { handleKeyDown }
222+ onMouseDown = { ( e ) => e . stopPropagation ( ) }
223+ onClick = { ( e ) => e . stopPropagation ( ) }
206224 autoFocus
207225 style = { { width : '100%' } }
208226 />
0 commit comments