diff --git a/croppa/main.py b/croppa/main.py index d08f867..d85ada6 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -2410,10 +2410,16 @@ class VideoEditor: if end_frame is None: end_frame = self.total_frames - 1 - # End the previous template at the current frame (if there is one) - if self.current_template_id is not None and self.current_template_id in self.templates: - self.templates[self.current_template_id]['end_frame'] = self.current_frame - 1 - print(f"DEBUG: Ended previous template {self.current_template_id} at frame {self.current_frame - 1}") + # End any templates that start after the current frame + for template_id, template_data in list(self.templates.items()): + if template_data['start_frame'] > self.current_frame: + # This template starts after the current frame, so remove it + del self.templates[template_id] + print(f"DEBUG: Removed future template {template_id} that started at frame {template_data['start_frame']}") + elif template_data['start_frame'] == self.current_frame: + # This template starts at the same frame, end it at the previous frame + self.templates[template_id]['end_frame'] = self.current_frame - 1 + print(f"DEBUG: Ended template {template_id} at frame {self.current_frame - 1}") self.templates[template_id] = { 'template': template.copy(),