55 LAST_SEARCH_FILES_KEYWORDS_TARGET_STATE_KEY ,
66 LAST_SEARCH_FILES_KEYWORDS_MATCH_MODE_STATE_KEY ,
77 LAST_SEARCH_FILES_FILENAME_MATCH_MODE_STATE_KEY ,
8- LAST_SEARCH_FILES_KEYWORDS_QUERY_STATE_KEY ,
9- LAST_SEARCH_FILES_FILENAME_QUERY_STATE_KEY
8+ LAST_SEARCH_FILES_KEYWORDS_QUERY_STATE_KEY
109} from '@/constants/state-keys'
1110import { prompt_for_keywords_target } from '../utils/prompt-for-keywords-target'
1211import { prompt_for_keywords_match_mode } from '../utils/prompt-for-keywords-match-mode'
@@ -30,98 +29,93 @@ export const perform_keywords_search_mode = async (params: {
3029 const local_queries : Record < string , string > = { }
3130
3231 while ( true ) {
33- const last_target =
34- params . extension_context . workspaceState . get <
35- 'contents' | 'filenames' | 'both'
36- > ( LAST_SEARCH_FILES_KEYWORDS_TARGET_STATE_KEY ) || 'contents'
32+ const state_key = LAST_SEARCH_FILES_KEYWORDS_QUERY_STATE_KEY
33+
34+ const initial_search_term =
35+ local_queries [ state_key ] !== undefined
36+ ? local_queries [ state_key ]
37+ : params . show_back_button
38+ ? ''
39+ : params . extension_context . workspaceState . get < string > ( state_key ) || ''
40+
41+ const result = await prompt_for_search_term (
42+ initial_search_term ,
43+ 'keywords' ,
44+ undefined ,
45+ ( value ) => {
46+ local_queries [ state_key ] = value
47+ if ( ! params . show_back_button ) {
48+ params . extension_context . workspaceState . update ( state_key , value )
49+ }
50+ }
51+ )
3752
38- const target_result = await prompt_for_keywords_target ( last_target )
39- if ( target_result == 'back' ) {
53+ if ( result . back ) {
4054 return 'back'
4155 }
42- if ( ! target_result ) return undefined
43-
44- const keywords_target = target_result
45- await params . extension_context . workspaceState . update (
46- LAST_SEARCH_FILES_KEYWORDS_TARGET_STATE_KEY ,
47- keywords_target
48- )
56+ if ( ! result . value ) return undefined
4957
50- let go_back_to_target = false
58+ const search_term_input = result . value
59+ local_queries [ state_key ] = search_term_input
5160
52- while ( true ) {
53- const match_mode_key =
54- keywords_target == 'filenames'
55- ? LAST_SEARCH_FILES_FILENAME_MATCH_MODE_STATE_KEY
56- : LAST_SEARCH_FILES_KEYWORDS_MATCH_MODE_STATE_KEY
61+ if ( ! params . show_back_button ) {
62+ await params . extension_context . workspaceState . update (
63+ state_key ,
64+ search_term_input
65+ )
66+ }
5767
58- const last_match_mode =
59- params . extension_context . workspaceState . get < 'all' | 'some' > (
60- match_mode_key
61- ) || 'all'
68+ const search_term = search_term_input . trim ( )
69+ if ( search_term . length == 0 ) return undefined
6270
63- const match_mode_result =
64- await prompt_for_keywords_match_mode ( last_match_mode )
71+ let go_back_to_term = false
6572
66- if ( match_mode_result == 'back' ) {
67- go_back_to_target = true
73+ while ( true ) {
74+ const last_target =
75+ params . extension_context . workspaceState . get <
76+ 'contents' | 'filenames' | 'both'
77+ > ( LAST_SEARCH_FILES_KEYWORDS_TARGET_STATE_KEY ) || 'contents'
78+
79+ const target_result = await prompt_for_keywords_target ( last_target )
80+ if ( target_result == 'back' ) {
81+ go_back_to_term = true
6882 break
6983 }
70- if ( ! match_mode_result ) return undefined
84+ if ( ! target_result ) return undefined
7185
72- const keywords_match_mode = match_mode_result
86+ const keywords_target = target_result
7387 await params . extension_context . workspaceState . update (
74- match_mode_key ,
75- keywords_match_mode
88+ LAST_SEARCH_FILES_KEYWORDS_TARGET_STATE_KEY ,
89+ keywords_target
7690 )
7791
78- let go_back_to_match_mode = false
92+ let go_back_to_target = false
7993
8094 while ( true ) {
81- const state_key =
95+ const match_mode_key =
8296 keywords_target == 'filenames'
83- ? LAST_SEARCH_FILES_FILENAME_QUERY_STATE_KEY
84- : LAST_SEARCH_FILES_KEYWORDS_QUERY_STATE_KEY
85-
86- const initial_search_term =
87- local_queries [ state_key ] !== undefined
88- ? local_queries [ state_key ]
89- : params . show_back_button
90- ? ''
91- : params . extension_context . workspaceState . get < string > (
92- state_key
93- ) || ''
94-
95- const result = await prompt_for_search_term (
96- initial_search_term ,
97- 'keywords' ,
98- keywords_target ,
99- ( value ) => {
100- local_queries [ state_key ] = value
101- if ( ! params . show_back_button ) {
102- params . extension_context . workspaceState . update ( state_key , value )
103- }
104- }
105- )
97+ ? LAST_SEARCH_FILES_FILENAME_MATCH_MODE_STATE_KEY
98+ : LAST_SEARCH_FILES_KEYWORDS_MATCH_MODE_STATE_KEY
10699
107- if ( result . back ) {
108- go_back_to_match_mode = true
109- break
110- }
111- if ( ! result . value ) return undefined
100+ const last_match_mode =
101+ params . extension_context . workspaceState . get < 'all' | 'some' > (
102+ match_mode_key
103+ ) || 'all'
112104
113- const search_term_input = result . value
114- local_queries [ state_key ] = search_term_input
105+ const match_mode_result =
106+ await prompt_for_keywords_match_mode ( last_match_mode )
115107
116- if ( ! params . show_back_button ) {
117- await params . extension_context . workspaceState . update (
118- state_key ,
119- search_term_input
120- )
108+ if ( match_mode_result == 'back' ) {
109+ go_back_to_target = true
110+ break
121111 }
112+ if ( ! match_mode_result ) return undefined
122113
123- const search_term = search_term_input . trim ( )
124- if ( search_term . length == 0 ) return undefined
114+ const keywords_match_mode = match_mode_result
115+ await params . extension_context . workspaceState . update (
116+ match_mode_key ,
117+ keywords_match_mode
118+ )
125119
126120 const files = await params . resolve_files ( )
127121
@@ -172,7 +166,7 @@ export const perform_keywords_search_mode = async (params: {
172166 continue
173167 }
174168
175- let go_back_to_term = false
169+ let go_back_to_match_mode = false
176170
177171 while ( true ) {
178172 const selected_items = await prompt_for_search_results ( {
@@ -184,7 +178,7 @@ export const perform_keywords_search_mode = async (params: {
184178 } )
185179
186180 if ( selected_items == 'back' ) {
187- go_back_to_term = true
181+ go_back_to_match_mode = true
188182 break
189183 }
190184
@@ -206,15 +200,15 @@ export const perform_keywords_search_mode = async (params: {
206200 return selected_items
207201 }
208202
209- if ( go_back_to_term ) continue
203+ if ( go_back_to_match_mode ) continue
210204 break
211205 }
212206
213- if ( go_back_to_match_mode ) continue
207+ if ( go_back_to_target ) continue
214208 break
215209 }
216210
217- if ( go_back_to_target ) continue
211+ if ( go_back_to_term ) continue
218212 break
219213 }
220214
0 commit comments