1
- use crossterm:: event:: { Event , KeyEvent , MouseEvent , MouseEventKind } ;
1
+ use crossterm:: event:: { Event , KeyEvent , MouseButton , MouseEvent , MouseEventKind } ;
2
+ use ratatui:: layout:: Rect ;
2
3
use tui_input:: { backend:: crossterm:: EventHandler , Input } ;
3
4
use tui_textarea:: TextArea ;
4
5
@@ -78,6 +79,7 @@ pub fn handle_mouse_events(mouse: MouseEvent, app: &mut App) {
78
79
// mouse scrolling is inverted
79
80
MouseEventKind :: ScrollDown => handle_block_scroll ( app, true , true , false ) ,
80
81
MouseEventKind :: ScrollUp => handle_block_scroll ( app, false , true , false ) ,
82
+ MouseEventKind :: Down ( MouseButton :: Left ) => handle_mouse_btn_press ( app, mouse) ,
81
83
_ => { /* do nothing */ }
82
84
}
83
85
}
@@ -185,12 +187,11 @@ fn handle_route_events(key: Key, app: &mut App) {
185
187
_ if key == DEFAULT_KEYBINDING . toggle_ignore_exp . key => {
186
188
app. data . decoder . ignore_exp = !app. data . decoder . ignore_exp ;
187
189
}
188
- // as these are tabs with index the order here matters, at least for readability
189
- _ => { }
190
+ _ => { /* Do nothing */ }
190
191
} ;
191
192
}
192
193
RouteId :: Encoder => {
193
- // todo!()
194
+ // nothing to handle
194
195
}
195
196
_ => { /* Do nothing */ }
196
197
}
@@ -201,11 +202,11 @@ fn handle_left_key_events(app: &mut App) {
201
202
match app. get_current_route ( ) . id {
202
203
RouteId :: Decoder => {
203
204
app. data . decoder . blocks . previous ( ) ;
204
- app. push_navigation_route ( app. data . decoder . blocks . get_active_route ( ) . clone ( ) ) ;
205
+ app. push_navigation_route ( * app. data . decoder . blocks . get_active_item ( ) ) ;
205
206
}
206
207
RouteId :: Encoder => {
207
208
app. data . encoder . blocks . previous ( ) ;
208
- app. push_navigation_route ( app. data . encoder . blocks . get_active_route ( ) . clone ( ) ) ;
209
+ app. push_navigation_route ( * app. data . encoder . blocks . get_active_item ( ) ) ;
209
210
}
210
211
RouteId :: Help => { /* Do nothing */ }
211
212
}
@@ -216,16 +217,46 @@ fn handle_right_key_events(app: &mut App) {
216
217
match app. get_current_route ( ) . id {
217
218
RouteId :: Decoder => {
218
219
app. data . decoder . blocks . next ( ) ;
219
- app. push_navigation_route ( app. data . decoder . blocks . get_active_route ( ) . clone ( ) ) ;
220
+ app. push_navigation_route ( * app. data . decoder . blocks . get_active_item ( ) ) ;
220
221
}
221
222
RouteId :: Encoder => {
222
223
app. data . encoder . blocks . next ( ) ;
223
- app. push_navigation_route ( app. data . encoder . blocks . get_active_route ( ) . clone ( ) ) ;
224
+ app. push_navigation_route ( * app. data . encoder . blocks . get_active_item ( ) ) ;
224
225
}
225
226
RouteId :: Help => { /* Do nothing */ }
226
227
}
227
228
}
228
229
230
+ fn handle_mouse_btn_press ( app : & mut App , mouse_event : MouseEvent ) {
231
+ if let Some ( data) = app
232
+ . block_map
233
+ . iter ( )
234
+ . filter ( |i| {
235
+ i. 0 . id == app. get_current_route ( ) . id
236
+ && i
237
+ . 1
238
+ . intersects ( Rect :: new ( mouse_event. column , mouse_event. row , 1 , 1 ) )
239
+ } )
240
+ . collect :: < Vec < _ > > ( )
241
+ . first ( )
242
+ {
243
+ let selected_route = * data. 0 ;
244
+
245
+ // route specific events
246
+ match app. get_current_route ( ) . id {
247
+ RouteId :: Decoder => {
248
+ app. data . decoder . blocks . set_item ( selected_route) ;
249
+ app. push_navigation_route ( * app. data . decoder . blocks . get_active_item ( ) ) ;
250
+ }
251
+ RouteId :: Encoder => {
252
+ app. data . encoder . blocks . set_item ( selected_route) ;
253
+ app. push_navigation_route ( * app. data . encoder . blocks . get_active_item ( ) ) ;
254
+ }
255
+ RouteId :: Help => { /* Do nothing */ }
256
+ }
257
+ } ;
258
+ }
259
+
229
260
fn handle_block_scroll ( app : & mut App , up : bool , is_mouse : bool , page : bool ) {
230
261
match app. get_current_route ( ) . active_block {
231
262
ActiveBlock :: Help => app. help_docs . handle_scroll ( up, page) ,
@@ -330,7 +361,7 @@ mod tests {
330
361
331
362
app. data . encoder . header . input_mode = InputMode :: Editing ;
332
363
333
- let route = app. main_tabs . set_index ( 1 ) . route . clone ( ) ;
364
+ let route = app. main_tabs . set_index ( 1 ) . route ;
334
365
app. push_navigation_route ( route) ;
335
366
336
367
assert_eq ! ( app. data. encoder. header. input_mode, InputMode :: Editing ) ;
0 commit comments