@@ -10,6 +10,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
1010 const [ synonymValidationStatus , setSynonymValidationStatus ] = useState ( { } )
1111 const { user } = useContext ( GlobalDataContext )
1212 const checkedSynonymsRef = useRef ( new Set ( ) )
13+ const preservedResultsRef = useRef ( [ ] ) // Store results during editing
1314
1415 const checkSynonym = useCallback ( async ( synonym , searchType ) => {
1516 try {
@@ -28,8 +29,17 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
2829 } , [ user ?. groupname ] )
2930
3031 const searchTerm = useCallback ( async ( searchTerm , searchType ) => {
31- if ( ! searchTerm || ! searchType || isEditing ) {
32+ if ( ! searchTerm || ! searchType ) {
3233 setSearchResults ( [ ] )
34+ preservedResultsRef . current = [ ]
35+ return
36+ }
37+
38+ // Don't search again if we're in editing mode, but preserve existing results
39+ if ( isEditing ) {
40+ if ( preservedResultsRef . current . length > 0 ) {
41+ setSearchResults ( preservedResultsRef . current )
42+ }
3343 return
3444 }
3545
@@ -50,6 +60,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
5060 } ) ) || [ ]
5161
5262 setSearchResults ( searchResults )
63+ preservedResultsRef . current = searchResults // Preserve for editing mode
5364 } catch ( error ) {
5465 if ( error ?. response ?. status === 409 && error ?. response ?. data ?. existing ) {
5566 onExactMatchChange ( true )
@@ -64,6 +75,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
6475 }
6576 )
6677 setSearchResults ( exactMatches )
78+ preservedResultsRef . current = exactMatches // Preserve exact matches too
6779 } else {
6880 onExactMatchChange ( false )
6981 setSearchResults ( [ ] )
@@ -98,6 +110,7 @@ export const useTermSearch = ({ term, type, synonyms, isEditing, onExactMatchCha
98110 useEffect ( ( ) => {
99111 if ( ! term ) {
100112 setSearchResults ( [ ] )
113+ preservedResultsRef . current = [ ] // Clear preserved results when no term
101114 onExactMatchChange ( false )
102115 return
103116 }
0 commit comments