@@ -93,131 +93,115 @@ export function YqlEditor({
9393 onCompletionIgnore,
9494 } ) ;
9595
96- const editorDidMount = React . useCallback (
97- ( editor : Monaco . editor . IStandaloneCodeEditor , monaco : typeof Monaco ) => {
98- window . ydbEditor = editor ;
99- const keybindings = getKeyBindings ( monaco ) ;
100- monaco . editor . registerCommand ( 'insertSnippetToEditor' , ( _asessor , input : string ) => {
101- //suggestController is not properly typed yet in monaco-editor package
102- const contribution = editor . getContribution < any > ( 'snippetController2' ) ;
103- if ( contribution ) {
104- editor . focus ( ) ;
105- editor . setValue ( '' ) ;
106- contribution . insert ( input ) ;
107- }
108- } ) ;
109-
110- if ( window . api . codeAssist ) {
111- registerMonacoGhost ( editor ) ;
112- prepareUserQueriesCache ( [
113- ...historyQueries . map ( ( query , index ) => ( {
114- name : `query${ index } .yql` ,
115- text : query . queryText ,
116- } ) ) ,
117- ...savedQueries . map ( ( query ) => ( {
118- name : query . name ,
119- text : query . body ,
120- } ) ) ,
121- ] ) ;
96+ const editorDidMount = ( editor : Monaco . editor . IStandaloneCodeEditor , monaco : typeof Monaco ) => {
97+ window . ydbEditor = editor ;
98+ const keybindings = getKeyBindings ( monaco ) ;
99+ monaco . editor . registerCommand ( 'insertSnippetToEditor' , ( _asessor , input : string ) => {
100+ //suggestController is not properly typed yet in monaco-editor package
101+ const contribution = editor . getContribution < any > ( 'snippetController2' ) ;
102+ if ( contribution ) {
103+ editor . focus ( ) ;
104+ editor . setValue ( '' ) ;
105+ contribution . insert ( input ) ;
122106 }
123- initResizeHandler ( editor ) ;
124- initUserPrompt ( editor , getLastQueryText ) ;
125- editor . focus ( ) ;
126- editor . addAction ( {
127- id : 'sendQuery' ,
128- label : i18n ( 'action.send-query' ) ,
129- keybindings : [ keybindings . sendQuery ] ,
130- // A precondition for this action.
131- precondition : undefined ,
132- // A rule to evaluate on top of the precondition in order to dispatch the keybindings.
133- keybindingContext : undefined ,
134- contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
135- contextMenuOrder : 1 ,
136- // Method that will be executed when the action is triggered.
137- // @param editor The editor instance is passed in as a convenience
138- run : ( ) => handleSendQuery ( ) ,
139- } ) ;
140-
141- const canSendSelectedText = editor . createContextKey < boolean > (
142- 'canSendSelectedText' ,
143- false ,
144- ) ;
145- editor . onDidChangeCursorSelection ( ( { selection, secondarySelections} ) => {
146- const notEmpty =
147- selection . selectionStartLineNumber !== selection . positionLineNumber ||
148- selection . selectionStartColumn !== selection . positionColumn ;
149- const hasMultipleSelections = secondarySelections . length > 0 ;
150- canSendSelectedText . set ( notEmpty && ! hasMultipleSelections ) ;
151- } ) ;
152- editor . addAction ( {
153- id : 'sendSelectedQuery' ,
154- label : i18n ( 'action.send-selected-query' ) ,
155- keybindings : [ keybindings . sendSelectedQuery ] ,
156- precondition : 'canSendSelectedText' ,
157- contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
158- contextMenuOrder : 1 ,
159- run : ( e ) => {
160- const selection = e . getSelection ( ) ;
161- const model = e . getModel ( ) ;
162- if ( selection && model ) {
163- const text = model . getValueInRange ( {
164- startLineNumber : selection . getSelectionStart ( ) . lineNumber ,
165- startColumn : selection . getSelectionStart ( ) . column ,
166- endLineNumber : selection . getPosition ( ) . lineNumber ,
167- endColumn : selection . getPosition ( ) . column ,
168- } ) ;
169- handleSendExecuteClick ( text , true ) ;
170- }
171- } ,
172- } ) ;
107+ } ) ;
173108
174- editor . addAction ( {
175- id : 'previous-query' ,
176- label : i18n ( 'action.previous-query' ) ,
177- keybindings : [ keybindings . selectPreviousQuery ] ,
178- contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
179- contextMenuOrder : 2 ,
180- run : ( ) => {
181- dispatch ( goToPreviousQuery ( ) ) ;
182- } ,
183- } ) ;
184- editor . addAction ( {
185- id : 'next-query' ,
186- label : i18n ( 'action.next-query' ) ,
187- keybindings : [ keybindings . selectNextQuery ] ,
188- contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
189- contextMenuOrder : 3 ,
190- run : ( ) => {
191- dispatch ( goToNextQuery ( ) ) ;
192- } ,
193- } ) ;
194- editor . addAction ( {
195- id : 'save-query' ,
196- label : i18n ( 'action.save-query' ) ,
197- keybindings : [ keybindings . saveQuery ] ,
198- run : ( ) => {
199- NiceModal . show ( SAVE_QUERY_DIALOG ) ;
200- } ,
201- } ) ;
109+ if ( window . api . codeAssist ) {
110+ registerMonacoGhost ( editor ) ;
111+ prepareUserQueriesCache ( [
112+ ...historyQueries . map ( ( query , index ) => ( {
113+ name : `query${ index } .yql` ,
114+ text : query . queryText ,
115+ } ) ) ,
116+ ...savedQueries . map ( ( query ) => ( {
117+ name : query . name ,
118+ text : query . body ,
119+ } ) ) ,
120+ ] ) ;
121+ }
122+ initResizeHandler ( editor ) ;
123+ initUserPrompt ( editor , getLastQueryText ) ;
124+ editor . focus ( ) ;
125+ editor . addAction ( {
126+ id : 'sendQuery' ,
127+ label : i18n ( 'action.send-query' ) ,
128+ keybindings : [ keybindings . sendQuery ] ,
129+ // A precondition for this action.
130+ precondition : undefined ,
131+ // A rule to evaluate on top of the precondition in order to dispatch the keybindings.
132+ keybindingContext : undefined ,
133+ contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
134+ contextMenuOrder : 1 ,
135+ // Method that will be executed when the action is triggered.
136+ // @param editor The editor instance is passed in as a convenience
137+ run : ( ) => handleSendQuery ( ) ,
138+ } ) ;
202139
203- return ( ) => {
204- if ( window . api . codeAssist ) {
205- dispose ( ) ;
140+ const canSendSelectedText = editor . createContextKey < boolean > ( 'canSendSelectedText' , false ) ;
141+ editor . onDidChangeCursorSelection ( ( { selection, secondarySelections} ) => {
142+ const notEmpty =
143+ selection . selectionStartLineNumber !== selection . positionLineNumber ||
144+ selection . selectionStartColumn !== selection . positionColumn ;
145+ const hasMultipleSelections = secondarySelections . length > 0 ;
146+ canSendSelectedText . set ( notEmpty && ! hasMultipleSelections ) ;
147+ } ) ;
148+ editor . addAction ( {
149+ id : 'sendSelectedQuery' ,
150+ label : i18n ( 'action.send-selected-query' ) ,
151+ keybindings : [ keybindings . sendSelectedQuery ] ,
152+ precondition : 'canSendSelectedText' ,
153+ contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
154+ contextMenuOrder : 1 ,
155+ run : ( e ) => {
156+ const selection = e . getSelection ( ) ;
157+ const model = e . getModel ( ) ;
158+ if ( selection && model ) {
159+ const text = model . getValueInRange ( {
160+ startLineNumber : selection . getSelectionStart ( ) . lineNumber ,
161+ startColumn : selection . getSelectionStart ( ) . column ,
162+ endLineNumber : selection . getPosition ( ) . lineNumber ,
163+ endColumn : selection . getPosition ( ) . column ,
164+ } ) ;
165+ handleSendExecuteClick ( text , true ) ;
206166 }
207- } ;
208- } ,
209- [
210- dispatch ,
211- dispose ,
212- getLastQueryText ,
213- handleSendExecuteClick ,
214- handleSendQuery ,
215- historyQueries ,
216- prepareUserQueriesCache ,
217- registerMonacoGhost ,
218- savedQueries ,
219- ] ,
220- ) ;
167+ } ,
168+ } ) ;
169+
170+ editor . addAction ( {
171+ id : 'previous-query' ,
172+ label : i18n ( 'action.previous-query' ) ,
173+ keybindings : [ keybindings . selectPreviousQuery ] ,
174+ contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
175+ contextMenuOrder : 2 ,
176+ run : ( ) => {
177+ dispatch ( goToPreviousQuery ( ) ) ;
178+ } ,
179+ } ) ;
180+ editor . addAction ( {
181+ id : 'next-query' ,
182+ label : i18n ( 'action.next-query' ) ,
183+ keybindings : [ keybindings . selectNextQuery ] ,
184+ contextMenuGroupId : CONTEXT_MENU_GROUP_ID ,
185+ contextMenuOrder : 3 ,
186+ run : ( ) => {
187+ dispatch ( goToNextQuery ( ) ) ;
188+ } ,
189+ } ) ;
190+ editor . addAction ( {
191+ id : 'save-query' ,
192+ label : i18n ( 'action.save-query' ) ,
193+ keybindings : [ keybindings . saveQuery ] ,
194+ run : ( ) => {
195+ NiceModal . show ( SAVE_QUERY_DIALOG ) ;
196+ } ,
197+ } ) ;
198+
199+ return ( ) => {
200+ if ( window . api . codeAssist ) {
201+ dispose ( ) ;
202+ }
203+ } ;
204+ } ;
221205
222206 const onChange = ( newValue : string ) => {
223207 updateErrorsHighlighting ( ) ;
0 commit comments