@@ -60,6 +60,7 @@ def perform_search(self, text):
6060 self .results = self .engine .run (text , folders )
6161 if self .results :
6262 self .results = [[result [0 ].replace (self .common_path .replace ('\" ' , '' ), '' ), result [1 ]] for result in self .results ]
63+ self .results .append ("``` List results in view" )
6364 self .window .show_quick_panel (self .results , self .goto_result )
6465 else :
6566 self .results = []
@@ -71,10 +72,21 @@ def perform_search(self, text):
7172
7273 def goto_result (self , file_no ):
7374 if file_no != - 1 :
74- file_name = self .common_path .replace ('\" ' , '' ) + self .results [file_no ][0 ]
75- view = self .window .open_file (file_name , sublime .ENCODED_POSITION )
76- regions = view .find_all (self .last_search_string )
77- view .add_regions ("search_in_project" , regions , "entity.name.filename.find-in-files" , "circle" , sublime .DRAW_OUTLINED )
75+ if file_no == len (self .results ) - 1 : # last result is "list in view"
76+ self .list_in_view ()
77+ else :
78+ file_name = self .common_path .replace ('\" ' , '' ) + self .results [file_no ][0 ]
79+ view = self .window .open_file (file_name , sublime .ENCODED_POSITION )
80+ regions = view .find_all (self .last_search_string )
81+ view .add_regions ("search_in_project" , regions , "entity.name.filename.find-in-files" , "circle" , sublime .DRAW_OUTLINED )
82+
83+ def list_in_view (self ):
84+ self .results .pop ()
85+ view = sublime .active_window ().new_file ()
86+ view .run_command ('search_in_project_results' ,
87+ {'query' : self .last_search_string ,
88+ 'results' : self .results ,
89+ 'common_path' : self .common_path .replace ('\" ' , '' )})
7890
7991 def search_folders (self ):
8092 search_folders = self .window .folders ()
@@ -97,3 +109,17 @@ def find_common_path(self, paths):
97109 else :
98110 break
99111 return "\" " + "/" .join (common_path ) + "/\" "
112+
113+ class SearchInProjectResultsCommand (sublime_plugin .TextCommand ):
114+ def format_result (self , common_path , result ):
115+ filename , row , column = result [0 ].split (':' )
116+ text = result [1 ]
117+ return "%s%s:\n %s: %s\n " % (common_path , filename , row , text )
118+
119+ def run (self , edit , common_path , results , query ):
120+ self .view .set_name ('Find Results' )
121+ self .view .set_scratch (True )
122+ self .view .set_syntax_file ('Packages/Default/Find Results.hidden-tmLanguage' )
123+ results_text = ("Search In Project results for \" %s\" \n \n " % query ) + "\n " .join ([self .format_result (common_path , result ) for result in results ])
124+ self .view .insert (edit , self .view .text_point (0 ,0 ), results_text )
125+
0 commit comments