From 0d203b3fd0852f01390455e2f46ce0ac97fa5c06 Mon Sep 17 00:00:00 2001 From: singerdmx Date: Mon, 21 Dec 2020 12:05:52 -0800 Subject: [PATCH] Fix delete button not working --- lib/models/documents/nodes/container.dart | 7 ++++++- lib/models/documents/nodes/line.dart | 2 +- lib/widgets/controller.dart | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/models/documents/nodes/container.dart b/lib/models/documents/nodes/container.dart index 08db8670..c5154622 100644 --- a/lib/models/documents/nodes/container.dart +++ b/lib/models/documents/nodes/container.dart @@ -59,7 +59,12 @@ abstract class Container extends Node { } ChildQuery queryChild(int offset, bool inclusive) { - assert(offset >= 0 && offset <= length); + if (offset < 0) { + throw ('Offset cannot be negative'); + } + if (offset > length) { + throw ('offset $offset > $length'); + } for (Node node in children) { int len = node.length; diff --git a/lib/models/documents/nodes/line.dart b/lib/models/documents/nodes/line.dart index 6323f2ec..537a14b8 100644 --- a/lib/models/documents/nodes/line.dart +++ b/lib/models/documents/nodes/line.dart @@ -128,7 +128,7 @@ class Line extends Container { super.delete(index, local); } - int remain = length - local; + int remain = len - local; if (remain > 0) { assert(nextLine != null); nextLine.delete(0, remain); diff --git a/lib/widgets/controller.dart b/lib/widgets/controller.dart index 9bfe8f71..e11ffe82 100644 --- a/lib/widgets/controller.dart +++ b/lib/widgets/controller.dart @@ -34,7 +34,12 @@ class QuillController extends ChangeNotifier { Delta delta; if (len > 0 || data is! String || (data as String).isNotEmpty) { - delta = document.replace(index, len, data); + try { + delta = document.replace(index, len, data); + } catch (e) { + print ('document.replace failed: $e'); + throw e; + } if (delta != null && toggledStyle.isNotEmpty && delta.isNotEmpty &&