Skip to content

Commit

Permalink
Handle null child query (#2151)
Browse files Browse the repository at this point in the history
* resolve todo about null child query (can cause exceptions occasionally when childQuery returns null)

* gaurd against null child query in collectStyles

---------

Co-authored-by: Jesse Ezell <[email protected]>
  • Loading branch information
jezell and timu-jesse-ezell authored Aug 26, 2024
1 parent 3c986be commit 932d466
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/src/document/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ class Document {
/// Special case of no-selection at start of empty line: gets inline style(s) from preceding non-empty line.
Style collectStyle(int index, int len) {
var res = queryChild(index);
if (res.node == null) {
return const Style();
}
if (len > 0) {
return (res.node as Line).collectStyle(res.offset, len);
}
Expand Down Expand Up @@ -267,11 +270,13 @@ class Document {
ChildQuery queryChild(int offset) {
// TODO: prevent user from moving caret after last line-break.
final res = _root.queryChild(offset, true);
if (res.node == null) {
return res;
}
if (res.node is Line) {
return res;
}
final block = res.node
as Block; // TODO: Can be nullable, handle this case to avoid cast exception
final block = res.node as Block;
return block.queryChild(res.offset, true);
}

Expand Down

0 comments on commit 932d466

Please sign in to comment.