@@ -42,77 +42,76 @@ define([
42
42
return rpc . execute ( "search/code" , _ . pick ( options , OPTIONS ) ) ;
43
43
} ;
44
44
45
- var doSearch = function ( _args ) {
46
- return searchCode ( _args )
47
- . then ( function ( results ) {
48
- return normResults ( results ) ;
49
- } )
50
- . then ( function ( buffer ) {
51
- return files . openNew ( "Find Results" , buffer ) ;
52
- } )
53
- . fail ( function ( err ) {
54
- console . error ( "error" , err ) ;
55
- } ) ;
56
- } ;
45
+
57
46
58
- // Command search code
59
- var commandSearch = Command . register ( "code.search" , {
60
- title : "Find in Files" ,
61
- category : "Find" ,
62
- shortcuts : [
63
- "mod+shift+f"
64
- ] ,
65
- action : function ( args ) {
47
+ var searchCommandHandler = function ( title , fields , forceOptions ) {
48
+ return function ( args ) {
66
49
if ( _ . isString ( args ) ) args = { 'query' : args } ;
67
50
args = _ . defaults ( args || { } , { } ) ;
68
51
52
+ var doSearch = function ( _args ) {
53
+ return searchCode ( _ . extend ( _args , forceOptions || { } ) )
54
+ . then ( function ( results ) {
55
+ return normResults ( results ) ;
56
+ } )
57
+ . then ( function ( buffer ) {
58
+ return files . openNew ( "Find Results" , buffer ) ;
59
+ } )
60
+ . fail ( function ( err ) {
61
+ console . error ( "error" , err ) ;
62
+ } ) ;
63
+ } ;
64
+
69
65
if ( ! args . query ) {
70
- return dialogs . fields ( "Find in Files" , {
71
- 'query' : {
72
- 'label' : "Find" ,
73
- 'type' : "text"
74
- } ,
75
- 'casesensitive' : {
76
- 'label' : "Case Sensitive" ,
77
- 'type' : "checkbox"
78
- }
79
- } , args )
66
+ return dialogs . fields ( title , fields , args )
80
67
. then ( doSearch ) ;
81
68
}
82
69
83
70
return doSearch ( args ) ;
84
71
}
72
+ } ;
73
+
74
+
75
+ // Command search code
76
+ var commandSearch = Command . register ( "code.search" , {
77
+ title : "Find in Files" ,
78
+ category : "Find" ,
79
+ shortcuts : [
80
+ "mod+shift+f"
81
+ ] ,
82
+ action : searchCommandHandler ( "Find in Files" , {
83
+ 'query' : {
84
+ 'label' : "Find" ,
85
+ 'type' : "text"
86
+ } ,
87
+ 'casesensitive' : {
88
+ 'label' : "Case Sensitive" ,
89
+ 'type' : "checkbox"
90
+ }
91
+ } )
85
92
} ) ;
86
93
87
94
// Command replace code
88
95
var commandReplace = Command . register ( "code.replace" , {
89
96
title : "Replace in Files" ,
90
97
category : "Find" ,
91
98
shortcuts : [ ] ,
92
- action : function ( args ) {
93
- if ( _ . isString ( args ) ) args = { 'query' : args } ;
94
- args = _ . defaults ( args || { } , { } ) ;
95
-
96
- if ( ! args . query ) {
97
- return dialogs . fields ( "Find and Replace in Files" , {
98
- 'query' : {
99
- 'label' : "Find" ,
100
- 'type' : "text"
101
- } ,
102
- 'replacement' : {
103
- 'label' : "Replace" ,
104
- 'type' : "text"
105
- } ,
106
- 'casesensitive' : {
107
- 'label' : "Case Sensitive" ,
108
- 'type' : "checkbox"
109
- }
110
- } , args )
111
- . then ( doSearch ) ;
99
+ action : searchCommandHandler ( "Find and Replace in Files" , {
100
+ 'query' : {
101
+ 'label' : "Find" ,
102
+ 'type' : "text"
103
+ } ,
104
+ 'replacement' : {
105
+ 'label' : "Replace" ,
106
+ 'type' : "text"
107
+ } ,
108
+ 'casesensitive' : {
109
+ 'label' : "Case Sensitive" ,
110
+ 'type' : "checkbox"
112
111
}
113
-
114
- return doSearch ( args ) ;
115
- }
112
+ } , {
113
+ replaceAll : true
114
+ } )
116
115
} )
117
116
118
117
0 commit comments