From 05022fbb986dd149665c188e73211a8bf583fdd9 Mon Sep 17 00:00:00 2001 From: Manfred Date: Tue, 1 Nov 2022 11:36:15 +0100 Subject: [PATCH] Fixed bug in undo when controller is in erase mode --- CHANGELOG.md | 9 ++++++--- example/lib/pencil_field_with_tools.dart | 9 +++------ example/pubspec.lock | 2 +- lib/src/controller.dart | 4 ++++ pubspec.yaml | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30ead91..6af3766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,10 +30,13 @@ * **BUGFIX** Using PencilController setDrawing could lead to an exception when called in write mode * **BUGFIX** Fixed images for comparison of drawing routines * **IMPROVEMENT** PencilDecorator can have custom callback to draw background -* **BREAKING** PencilDecorator now accepts either number of lines or a fixed spacing to draw ruled, - chequered or dotted pattern +* **BREAKING** PencilDecorator now accepts either number of lines or a fixed spacing to draw ruled, chequered or dotted pattern * **DOCUMENTATION** Improved example ## 0.2.1 -* **BUGFIX** Changed signature of custom painter function in PencilDecoration \ No newline at end of file +* **BUGFIX** Changed signature of custom painter function in PencilDecoration + +## 0.2.2 + +* **BUGFIX** Fixed bug in undo method when controller is in erase mode diff --git a/example/lib/pencil_field_with_tools.dart b/example/lib/pencil_field_with_tools.dart index fe8bb89..a6f4807 100644 --- a/example/lib/pencil_field_with_tools.dart +++ b/example/lib/pencil_field_with_tools.dart @@ -93,15 +93,12 @@ class _PencilFieldWithToolsState extends State { }); } - /*void _onModeSelected(PencilMode newMode) { + void _onPrintJSON() { setState(() { - widget.controller.setMode(PencilMode.erase); - pencilPaint = eraserPaint; + widget.controller.undo(); }); - }*/ - void _onPrintJSON() { - log(widget.controller.drawing.toJson().toString()); + //log(widget.controller.drawing.toJson().toString()); } } diff --git a/example/pubspec.lock b/example/pubspec.lock index 37addec..3ea49c2 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -122,7 +122,7 @@ packages: path: ".." relative: true source: path - version: "0.2.0" + version: "0.2.1" sky_engine: dependency: transitive description: flutter diff --git a/lib/src/controller.dart b/lib/src/controller.dart index 1e3058a..dec3937 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -223,9 +223,13 @@ class PencilFieldController { void undo() { if (_undoPaths.strokeCount == 0) return; + // Move the last deleted stroke back to the list of strokes _strokePaths = _strokePaths.add(_undoPaths.lastStroke); _totalSize = null; _undoPaths.removeLast(); + + // Add an additional entry to the list of markers. + _writePathsMarkedForErase.add(false); } void clear() { diff --git a/pubspec.yaml b/pubspec.yaml index 51c0912..ba4fb6a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: pencil_field description: Pencil / stylus interaction (writing & erasing) on different devices and platforms. Comes with versioned persistence of input. -version: 0.2.1 +version: 0.2.2 homepage: https://github.com/ManfredM/pencil_field environment: