@@ -9,7 +9,7 @@ use crate::{float::FloatContent, hint::Shortcut};
9
9
use linutil_core:: Command ;
10
10
11
11
use ratatui:: {
12
- crossterm:: event:: { KeyCode , KeyEvent , MouseEvent , MouseEventKind } ,
12
+ crossterm:: event:: { KeyCode , KeyEvent , MouseButton , MouseEvent , MouseEventKind } ,
13
13
layout:: Rect ,
14
14
style:: { Style , Stylize } ,
15
15
text:: Line ,
@@ -33,6 +33,8 @@ pub struct FloatingText {
33
33
mode_title : String ,
34
34
wrap_words : bool ,
35
35
frame_height : usize ,
36
+ drag_start_y : Option < u16 > ,
37
+ drag_start_scroll : Option < usize > ,
36
38
}
37
39
38
40
macro_rules! style {
@@ -141,6 +143,8 @@ impl FloatingText {
141
143
h_scroll : 0 ,
142
144
wrap_words,
143
145
frame_height : 0 ,
146
+ drag_start_y : None ,
147
+ drag_start_scroll : None ,
144
148
}
145
149
}
146
150
@@ -165,6 +169,8 @@ impl FloatingText {
165
169
v_scroll : 0 ,
166
170
wrap_words : false ,
167
171
frame_height : 0 ,
172
+ drag_start_y : None ,
173
+ drag_start_scroll : None ,
168
174
} )
169
175
}
170
176
@@ -206,6 +212,19 @@ impl FloatingText {
206
212
} ;
207
213
}
208
214
}
215
+
216
+ fn handle_drag ( & mut self , current_y : u16 ) {
217
+ if let ( Some ( start_y) , Some ( start_scroll) ) = ( self . drag_start_y , self . drag_start_scroll ) {
218
+ let delta = start_y as i32 - current_y as i32 ;
219
+ let new_scroll = start_scroll as i32 + delta;
220
+
221
+ let max_scroll = self
222
+ . wrapped_lines
223
+ . len ( )
224
+ . saturating_sub ( self . frame_height . saturating_sub ( 2 ) ) ;
225
+ self . v_scroll = new_scroll. clamp ( 0 , max_scroll as i32 ) as usize ;
226
+ }
227
+ }
209
228
}
210
229
211
230
impl FloatContent for FloatingText {
@@ -285,6 +304,17 @@ impl FloatContent for FloatingText {
285
304
286
305
fn handle_mouse_event ( & mut self , event : & MouseEvent ) -> bool {
287
306
match event. kind {
307
+ MouseEventKind :: Down ( MouseButton :: Left ) => {
308
+ self . drag_start_y = Some ( event. row ) ;
309
+ self . drag_start_scroll = Some ( self . v_scroll ) ;
310
+ }
311
+ MouseEventKind :: Up ( MouseButton :: Left ) => {
312
+ self . drag_start_y = None ;
313
+ self . drag_start_scroll = None ;
314
+ }
315
+ MouseEventKind :: Drag ( MouseButton :: Left ) => {
316
+ self . handle_drag ( event. row ) ;
317
+ }
288
318
MouseEventKind :: ScrollDown => self . scroll_down ( ) ,
289
319
MouseEventKind :: ScrollUp => self . scroll_up ( ) ,
290
320
MouseEventKind :: ScrollLeft => self . scroll_left ( ) ,
0 commit comments