From 9344355d0e7f31403bd093fe9a7ae401f0d16ea5 Mon Sep 17 00:00:00 2001 From: Bilal Ishaq Date: Sat, 7 Mar 2026 19:51:02 +0500 Subject: [PATCH 1/2] Fix crash when inserting newlines rapidly --- .../lib/src/rendering/editable_box.dart | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/fleather/lib/src/rendering/editable_box.dart b/packages/fleather/lib/src/rendering/editable_box.dart index 51efbfe5..bba9f150 100644 --- a/packages/fleather/lib/src/rendering/editable_box.dart +++ b/packages/fleather/lib/src/rendering/editable_box.dart @@ -243,21 +243,23 @@ class RenderEditableContainerBox extends RenderBox /// The `position` parameter is expected to be relative to the [node] of /// this container. RenderEditableBox childAtPosition(TextPosition position) { - assert(firstChild != null); + assert(firstChild != null); - final targetNode = node.lookup(position.offset).node; + final targetNode = node.lookup(position.offset).node; - var targetChild = firstChild; - while (targetChild != null) { - if (targetChild.node == targetNode) { - break; - } - targetChild = childAfter(targetChild); + RenderEditableBox? targetChild = firstChild; + + while (targetChild != null) { + if (targetChild.node == targetNode) { + return targetChild; } - assert(targetChild != null, 'No child at position $position'); - return targetChild!; + targetChild = childAfter(targetChild); } + // Fallback: return last available child instead of crashing + return lastChild!; +} + /// Returns child of this container located at the specified local `offset`. /// /// If `offset` is above this container (offset.dy is negative) returns From ac696ee2bf26203ffc54c6ae9f6b96c6fc178b41 Mon Sep 17 00:00:00 2001 From: Alan Mantoux Date: Tue, 9 Jun 2026 07:53:29 +0200 Subject: [PATCH 2/2] dart format --- .../lib/src/rendering/editable_box.dart | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/fleather/lib/src/rendering/editable_box.dart b/packages/fleather/lib/src/rendering/editable_box.dart index bba9f150..f85ae3f0 100644 --- a/packages/fleather/lib/src/rendering/editable_box.dart +++ b/packages/fleather/lib/src/rendering/editable_box.dart @@ -243,22 +243,22 @@ class RenderEditableContainerBox extends RenderBox /// The `position` parameter is expected to be relative to the [node] of /// this container. RenderEditableBox childAtPosition(TextPosition position) { - assert(firstChild != null); + assert(firstChild != null); - final targetNode = node.lookup(position.offset).node; + final targetNode = node.lookup(position.offset).node; - RenderEditableBox? targetChild = firstChild; + RenderEditableBox? targetChild = firstChild; - while (targetChild != null) { - if (targetChild.node == targetNode) { - return targetChild; + while (targetChild != null) { + if (targetChild.node == targetNode) { + return targetChild; + } + targetChild = childAfter(targetChild); } - targetChild = childAfter(targetChild); - } - // Fallback: return last available child instead of crashing - return lastChild!; -} + // Fallback: return last available child instead of crashing + return lastChild!; + } /// Returns child of this container located at the specified local `offset`. ///