@@ -90,6 +90,43 @@ impl SearchResult {
90
90
self . command_tx . as_ref ( ) . unwrap ( ) . send ( action) . unwrap ( ) ;
91
91
}
92
92
93
+ fn top ( & mut self , state : & State ) {
94
+ if state. search_result . list . is_empty ( ) {
95
+ return ;
96
+ }
97
+
98
+ self . state . select ( Some ( 0 ) ) ;
99
+ let selected_result = state. search_result . list . first ( ) . unwrap ( ) ;
100
+ let action = AppAction :: Action ( Action :: SetSelectedResult {
101
+ result : SearchResultState {
102
+ index : selected_result. index ,
103
+ path : selected_result. path . clone ( ) ,
104
+ matches : selected_result. matches . clone ( ) ,
105
+ total_matches : selected_result. total_matches ,
106
+ } ,
107
+ } ) ;
108
+ self . command_tx . as_ref ( ) . unwrap ( ) . send ( action) . unwrap ( ) ;
109
+ }
110
+
111
+ fn bottom ( & mut self , state : & State ) {
112
+ if state. search_result . list . is_empty ( ) {
113
+ return ;
114
+ }
115
+
116
+ let i = state. search_result . list . len ( ) - 1 ;
117
+ self . state . select ( Some ( i) ) ;
118
+ let selected_result = state. search_result . list . get ( i) . unwrap ( ) ;
119
+ let action = AppAction :: Action ( Action :: SetSelectedResult {
120
+ result : SearchResultState {
121
+ index : selected_result. index ,
122
+ path : selected_result. path . clone ( ) ,
123
+ matches : selected_result. matches . clone ( ) ,
124
+ total_matches : selected_result. total_matches ,
125
+ } ,
126
+ } ) ;
127
+ self . command_tx . as_ref ( ) . unwrap ( ) . send ( action) . unwrap ( ) ;
128
+ }
129
+
93
130
fn calculate_total_matches ( & mut self , search_result_state : & SearchResultState ) -> & str {
94
131
let total_matches: usize = search_result_state. matches . iter ( ) . map ( |m| m. submatches . len ( ) ) . sum ( ) ;
95
132
let total_matches_str = total_matches. to_string ( ) ;
@@ -119,20 +156,28 @@ impl Component for SearchResult {
119
156
120
157
fn handle_key_events ( & mut self , key : KeyEvent , state : & State ) -> Result < Option < AppAction > > {
121
158
if state. active_tab == Tab :: SearchResult {
122
- match key. code {
123
- KeyCode :: Char ( 'd' ) => {
159
+ match ( key. code , key . modifiers ) {
160
+ ( KeyCode :: Char ( 'd' ) , _ ) => {
124
161
self . delete_file ( & state. selected_result ) ;
125
162
Ok ( None )
126
163
} ,
127
- KeyCode :: Char ( 'j' ) => {
164
+ ( KeyCode :: Char ( 'g' ) , _) => {
165
+ self . top ( state) ;
166
+ Ok ( None )
167
+ } ,
168
+ ( KeyCode :: Char ( 'G' ) , _) => {
169
+ self . bottom ( state) ;
170
+ Ok ( None )
171
+ } ,
172
+ ( KeyCode :: Char ( 'j' ) , _) => {
128
173
self . next ( state) ;
129
174
Ok ( None )
130
175
} ,
131
- KeyCode :: Char ( 'k' ) => {
176
+ ( KeyCode :: Char ( 'k' ) , _ ) => {
132
177
self . previous ( state) ;
133
178
Ok ( None )
134
179
} ,
135
- KeyCode :: Enter => {
180
+ ( KeyCode :: Enter , _ ) => {
136
181
let action = AppAction :: Action ( Action :: SetActiveTab { tab : Tab :: Preview } ) ;
137
182
self . command_tx . as_ref ( ) . unwrap ( ) . send ( action) . unwrap ( ) ;
138
183
Ok ( None )
@@ -155,13 +200,15 @@ impl Component for SearchResult {
155
200
block
156
201
} ;
157
202
203
+ let project_root = state. project_root . to_string_lossy ( ) ;
158
204
let list_items: Vec < ListItem > = state
159
205
. search_result
160
206
. list
161
207
. iter ( )
162
208
. map ( |s| {
163
209
let text = Line :: from ( vec ! [
164
- Span :: raw( & s. path) ,
210
+ // Display the relative path
211
+ Span :: raw( s. path. strip_prefix( format!( "{}/" , project_root) . as_str( ) ) . unwrap_or( & s. path) ) ,
165
212
Span :: raw( " (" ) ,
166
213
Span :: styled( s. total_matches. to_string( ) , Style :: default ( ) . fg( Color :: Yellow ) ) ,
167
214
Span :: raw( ")" ) ,
0 commit comments