From 655dca401472e4efd521782a1fabec67c5807497 Mon Sep 17 00:00:00 2001 From: hm21 Date: Fri, 17 Apr 2026 11:14:46 +0200 Subject: [PATCH] feat: implement replaceHistory() method to allow replacing history entries in the stack --- CHANGELOG.md | 3 +++ .../main_editor/services/state_manager.dart | 22 +++++++++++++++++++ pubspec.yaml | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf6aa37..ac75e38d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 12.4.2 +- **FEAT**(state-manager): Add `replaceHistory()` to replace an existing history entry in the stack (current pointer by default, or a custom index). + ## 12.4.1 - **FEAT**(main-editor): Add `captureImageOnDone` to `MainEditorConfigs` (default `true`) to make final `captureEditorImage()` on done optional. - **FIX**(main-editor): Prevent `_isProcessingFinalImage` from getting stuck by guarding done-flow cleanup with `try/finally`. diff --git a/lib/features/main_editor/services/state_manager.dart b/lib/features/main_editor/services/state_manager.dart index d4c0352f..b8ad25d0 100644 --- a/lib/features/main_editor/services/state_manager.dart +++ b/lib/features/main_editor/services/state_manager.dart @@ -285,6 +285,28 @@ class StateManager { if (!skipUpdateActiveItems) updateActiveItems(); } + /// Replaces a history entry in the stack. + /// + /// By default, the currently active history entry is replaced. You can + /// provide [index] to replace any specific history position. + /// + /// Throws an [ArgumentError] when [index] is out of range. + void replaceHistory( + EditorStateHistory history, { + int? index, + bool skipUpdateActiveItems = false, + }) { + final targetIndex = index ?? _historyPointer; + + if (targetIndex < 0 || targetIndex >= _stateHistory.length) { + throw ArgumentError('History index out of range'); + } + + _stateHistory[targetIndex] = history; + + if (!skipUpdateActiveItems) updateActiveItems(); + } + /// Redoes the last undone change, moving the history pointer forward by one /// step. /// If there is no forward change available, this operation will throw an diff --git a/pubspec.yaml b/pubspec.yaml index 7e4ea39e..21a0ba4c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pro_image_editor description: "A Flutter image editor: Seamlessly enhance your images with user-friendly editing features." -version: 12.4.1 +version: 12.4.2 homepage: https://github.com/hm21/pro_image_editor/ repository: https://github.com/hm21/pro_image_editor/ documentation: https://github.com/hm21/pro_image_editor/