From 7f08f3845711d43f1ad5ee389dfa391fbcbed2ae Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 7 Sep 2025 22:50:48 +0200 Subject: [PATCH] refactor(main.py): update last seek time on key press to prevent auto-repeat timeout and handle different key presses --- croppa/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/croppa/main.py b/croppa/main.py index 1415162..08cb4ce 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -525,6 +525,8 @@ class VideoEditor: self.auto_repeat_direction == direction and self.auto_repeat_shift == shift_pressed and self.auto_repeat_ctrl == ctrl_pressed): + # Just update the last seek time to prevent timeout + self.last_seek_time = time.time() return self.auto_repeat_active = True @@ -533,7 +535,7 @@ class VideoEditor: self.auto_repeat_shift = shift_pressed self.auto_repeat_ctrl = ctrl_pressed self.key_first_press_time = time.time() - self.last_seek_time = 0 + self.last_seek_time = time.time() # Initialize to current time # Do initial seek immediately self.seek_video_with_modifier(direction, shift_pressed, ctrl_pressed) @@ -1816,14 +1818,17 @@ class VideoEditor: delay = self.calculate_frame_delay() if self.is_playing else 30 key = cv2.waitKey(delay) & 0xFF - # Handle auto-repeat timeout - only stop if no key is pressed for a longer period + # Handle auto-repeat - stop if a different key is pressed or no key for too long if key == 255 and self.auto_repeat_active: # 255 means no key pressed # Check if enough time has passed since last key press - if time.time() - self.last_seek_time > 0.3: # 300ms timeout (increased) + if time.time() - self.last_seek_time > 1.0: # 1 second timeout self.stop_auto_repeat_seek() elif key != 255 and self.auto_repeat_active: # A key is pressed, update the last seek time to prevent timeout self.last_seek_time = time.time() + # If it's a different key, stop auto-repeat + if key != self.auto_repeat_key: + self.stop_auto_repeat_seek() # Get modifier key states window_title = "Image Editor" if self.is_image_mode else "Video Editor"