@@ -34,63 +34,88 @@ export const search_files_for_context_commands = (
3434 LAST_SEARCH_FILES_FOR_CONTEXT_QUERY_STATE_KEY
3535 ) || ''
3636
37+ let skip_input = false
38+ const is_context_menu = item !== undefined
39+
40+ if ( is_context_menu ) {
41+ const active_editor = vscode . window . activeTextEditor
42+ if ( active_editor ) {
43+ const selection = active_editor . selection
44+ if ( ! selection . isEmpty ) {
45+ const selected_text = active_editor . document . getText ( selection ) . trim ( )
46+ if ( selected_text . length > 0 ) {
47+ initial_keywords = selected_text
48+ skip_input = true
49+ }
50+ }
51+ }
52+ }
53+
3754 while ( true ) {
3855 try {
39- const input_box = vscode . window . createInputBox ( )
40- input_box . title = t ( 'command.search.title' )
41- input_box . prompt = t ( 'command.search.prompt' )
42- input_box . placeholder = t ( 'command.search.placeholder' )
43- input_box . value = initial_keywords
44-
4556 const close_button = {
4657 iconPath : new vscode . ThemeIcon ( 'close' ) ,
4758 tooltip : t ( 'common.close' )
4859 }
4960
50- input_box . buttons = [ close_button ]
61+ let keywords_input : string | undefined
5162
52- const result = await new Promise < { value : string | undefined } > (
53- ( resolve ) => {
54- let is_resolved = false
55- const disposables : vscode . Disposable [ ] = [ ]
56-
57- disposables . push (
58- input_box . onDidTriggerButton ( ( button ) => {
59- if ( button === close_button ) {
60- resolve ( { value : undefined } )
63+ if ( skip_input ) {
64+ keywords_input = initial_keywords
65+ skip_input = false
66+ } else {
67+ const input_box = vscode . window . createInputBox ( )
68+ input_box . title = t ( 'command.search.title' )
69+ input_box . prompt = t ( 'command.search.prompt' )
70+ input_box . placeholder = t ( 'command.search.placeholder' )
71+ input_box . value = initial_keywords
72+
73+ input_box . buttons = [ close_button ]
74+
75+ const result = await new Promise < { value : string | undefined } > (
76+ ( resolve ) => {
77+ let is_resolved = false
78+ const disposables : vscode . Disposable [ ] = [ ]
79+
80+ disposables . push (
81+ input_box . onDidTriggerButton ( ( button ) => {
82+ if ( button === close_button ) {
83+ resolve ( { value : undefined } )
84+ input_box . hide ( )
85+ }
86+ } ) ,
87+ input_box . onDidAccept ( ( ) => {
88+ const value = input_box . value . trim ( )
89+ if ( value . length == 0 ) {
90+ input_box . validationMessage = t (
91+ 'command.search.validation-empty'
92+ )
93+ return
94+ }
95+ is_resolved = true
96+ resolve ( { value } )
6197 input_box . hide ( )
62- }
63- } ) ,
64- input_box . onDidAccept ( ( ) => {
65- const value = input_box . value . trim ( )
66- if ( value . length == 0 ) {
67- input_box . validationMessage = t (
68- 'command.search.validation-empty'
69- )
70- return
71- }
72- is_resolved = true
73- resolve ( { value } )
74- input_box . hide ( )
75- } ) ,
76- input_box . onDidChangeValue ( ( ) => {
77- if ( input_box . value . trim ( ) . length > 0 ) {
78- input_box . validationMessage = undefined
79- }
80- } ) ,
81- input_box . onDidHide ( ( ) => {
82- if ( ! is_resolved ) {
83- resolve ( { value : undefined } )
84- }
85- disposables . forEach ( ( d ) => d . dispose ( ) )
86- input_box . dispose ( )
87- } )
88- )
89- input_box . show ( )
90- }
91- )
98+ } ) ,
99+ input_box . onDidChangeValue ( ( ) => {
100+ if ( input_box . value . trim ( ) . length > 0 ) {
101+ input_box . validationMessage = undefined
102+ }
103+ } ) ,
104+ input_box . onDidHide ( ( ) => {
105+ if ( ! is_resolved ) {
106+ resolve ( { value : undefined } )
107+ }
108+ disposables . forEach ( ( d ) => d . dispose ( ) )
109+ input_box . dispose ( )
110+ } )
111+ )
112+ input_box . show ( )
113+ }
114+ )
115+
116+ keywords_input = result . value
117+ }
92118
93- const keywords_input = result . value
94119 if ( ! keywords_input ) return
95120
96121 await extension_context . workspaceState . update (
@@ -373,8 +398,9 @@ export const search_files_for_context_commands = (
373398 }
374399
375400 return [
376- vscode . commands . registerCommand ( 'codeWebChat.searchFilesForContext' , ( ) =>
377- search_handler ( )
401+ vscode . commands . registerCommand (
402+ 'codeWebChat.searchFilesForContext' ,
403+ ( item ?: any ) => search_handler ( item )
378404 ) ,
379405 vscode . commands . registerCommand (
380406 'codeWebChat.searchFilesForContextFromDirectory' ,
0 commit comments