@@ -13,25 +13,33 @@ import { ILabelService } from 'vs/platform/label/common/label';
1313import { SearchResult } from 'vs/workbench/contrib/search/common/searchModel' ;
1414import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
1515import { SearchEditor } from 'vs/workbench/contrib/search/browser/searchEditor' ;
16- import { getOrMakeSearchEditorInput } from 'vs/workbench/contrib/search/browser/searchEditorInput' ;
16+ import { getOrMakeSearchEditorInput , SearchEditorInput } from 'vs/workbench/contrib/search/browser/searchEditorInput' ;
1717import { serializeSearchResultForEditor , serializeSearchConfiguration } from 'vs/workbench/contrib/search/browser/searchEditorSerialization' ;
1818
19+
1920export const openNewSearchEditor =
2021 async ( editorService : IEditorService , instantiationService : IInstantiationService ) => {
2122 const activeEditor = editorService . activeTextEditorWidget ;
2223 let activeModel : ICodeEditor | undefined ;
23- if ( isDiffEditor ( activeEditor ) ) {
24- if ( activeEditor . getOriginalEditor ( ) . hasTextFocus ( ) ) {
25- activeModel = activeEditor . getOriginalEditor ( ) ;
24+ let selected = '' ;
25+ if ( activeEditor ) {
26+ if ( isDiffEditor ( activeEditor ) ) {
27+ if ( activeEditor . getOriginalEditor ( ) . hasTextFocus ( ) ) {
28+ activeModel = activeEditor . getOriginalEditor ( ) ;
29+ } else {
30+ activeModel = activeEditor . getModifiedEditor ( ) ;
31+ }
2632 } else {
27- activeModel = activeEditor . getModifiedEditor ( ) ;
33+ activeModel = activeEditor as ICodeEditor ;
2834 }
35+ const selection = activeModel ?. getSelection ( ) ;
36+ selected = ( selection && activeModel ?. getModel ( ) ?. getValueInRange ( selection ) ) ?? '' ;
2937 } else {
30- activeModel = activeEditor as ICodeEditor | undefined ;
38+ if ( editorService . activeEditor instanceof SearchEditorInput ) {
39+ const active = editorService . activeControl as SearchEditor ;
40+ selected = active . getSelected ( ) ;
41+ }
3142 }
32- const selection = activeModel ?. getSelection ( ) ;
33- let selected = ( selection && activeModel ?. getModel ( ) ?. getValueInRange ( selection ) ) ?? '' ;
34-
3543
3644 const input = instantiationService . invokeFunction ( getOrMakeSearchEditorInput , { text : serializeSearchConfiguration ( { query : selected } ) } ) ;
3745 await editorService . openEditor ( input , { pinned : true } ) ;
0 commit comments