From 6f75b1738d4c8753966826ac3d727dc00edc76ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E7=94=B1=E7=9A=84=E4=B8=96=E7=95=8C=E4=BA=BA?= <3196812536@qq.com> Date: Thu, 22 May 2025 21:24:40 +0800 Subject: [PATCH] fix: #6301 (#6317) * fix: #6301 * fix: update dependencies in useUpdateHandler and add eslint comment in ContentSearch --- src/renderer/src/components/ContentSearch.tsx | 10 +++++----- src/renderer/src/hooks/useUpdateHandler.ts | 2 +- src/renderer/src/pages/home/Inputbar/Inputbar.tsx | 9 +++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/components/ContentSearch.tsx b/src/renderer/src/components/ContentSearch.tsx index c43021b7ad..08a1fd415a 100644 --- a/src/renderer/src/components/ContentSearch.tsx +++ b/src/renderer/src/components/ContentSearch.tsx @@ -399,6 +399,7 @@ export const ContentSearch = React.forwardRef( searchInputFocus() } + // eslint-disable-next-line react-hooks/exhaustive-deps const implementation = { disable() { setEnableContentSearch(false) @@ -526,8 +527,7 @@ export const ContentSearch = React.forwardRef( if (enableContentSearch && searchInputRef.current?.value.trim()) { implementation.search() } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isCaseSensitive, isWholeWord, enableContentSearch]) // Add enableContentSearch dependency + }, [isCaseSensitive, isWholeWord, enableContentSearch, implementation]) // Add enableContentSearch dependency const prevButtonOnClick = () => { implementation.searchPrev() @@ -690,18 +690,18 @@ const SearchResults = styled.div` width: 80px; margin: 0 2px; flex: 0 0 auto; - color: var(--color-text-secondary); + color: var(--color-text-1); font-size: 14px; font-family: Ubuntu; ` const SearchResultsPlaceholder = styled.span` - color: var(--color-text-secondary); + color: var(--color-text-1); opacity: 0.5; ` const NoResults = styled.span` - color: var(--color-text-secondary); + color: var(--color-text-1); ` const SearchResultCount = styled.span` diff --git a/src/renderer/src/hooks/useUpdateHandler.ts b/src/renderer/src/hooks/useUpdateHandler.ts index 8b2f2800c6..fe4d8f631c 100644 --- a/src/renderer/src/hooks/useUpdateHandler.ts +++ b/src/renderer/src/hooks/useUpdateHandler.ts @@ -85,5 +85,5 @@ export default function useUpdateHandler() { }) ] return () => removers.forEach((remover) => remover()) - }, [dispatch, t]) + }, [dispatch, notificationService, t]) } diff --git a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx index 5c3288d025..c4a919d8f3 100644 --- a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx @@ -434,7 +434,7 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = const text = textArea.value let match = text.slice(cursorPosition + selectionLength).match(/\$\{[^}]+\}/) - let startIndex = -1 + let startIndex: number if (!match) { match = text.match(/\$\{[^}]+\}/) @@ -764,7 +764,12 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = if (document.activeElement?.closest('.ant-modal')) { return } - textareaRef.current?.focus() + + const lastFocusedComponent = PasteService.getLastFocusedComponent() + + if (!lastFocusedComponent || lastFocusedComponent === 'inputbar') { + textareaRef.current?.focus() + } } window.addEventListener('focus', onFocus) return () => window.removeEventListener('focus', onFocus)