From 27ed93970fab1f0fd0c01cef5b1cb2c0a361aab2 Mon Sep 17 00:00:00 2001 From: singerdmx Date: Tue, 29 Dec 2020 15:06:37 -0800 Subject: [PATCH] Fix Undo throw Offset cannot be negative --- lib/widgets/controller.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index 83a27bbc..4bfc5a4f 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -44,13 +44,23 @@ class QuillController extends ChangeNotifier { void undo() { if (document.undo()) { - notifyListeners(); + if (this.selection.extentOffset >= document.length) { + updateSelection(TextSelection.collapsed(offset: document.length), + ChangeSource.LOCAL); + } else { + notifyListeners(); + } } } void redo() { if (document.redo()) { - notifyListeners(); + if (this.selection.extentOffset >= document.length) { + updateSelection(TextSelection.collapsed(offset: document.length), + ChangeSource.LOCAL); + } else { + notifyListeners(); + } } }